how to pass variable from one event to the other?

B

Ben

Hi,

I need to use the value of a variable generated in the
'SelectedIndexChanged' event of a gridview in the 'RowUpdating' event.
I tried this below, but the variable generated in the 'SelectedIndexChanged'
event loses its value when starting the RowUpdating' event.
I think it has something to do with the postback and so refreshing the page
....

How can i do that?
Thanks
Ben

the code:

Friend myvar As String

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim row As GridViewRow = GridView1.SelectedRow
myvar = row.Cells(2).Text 'this is ok
end Sub


Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating
response.write(myvar) 'this gives nothing
 
T

tommaso.gastaldi

You could simply store it in a session variable and retrieve it when
you need
across postbacks:

store:
Session("myvar") = myvar

retrieve:
myvar = Session("myvar")

Better anyway always to check if Nothing in case expired

If myvar IsNot Nothing Then
'...
Else
'Inform user
End If

Tommaso

Ben ha scritto:
 
B

Ben

Thanks

You could simply store it in a session variable and retrieve it when
you need
across postbacks:

store:
Session("myvar") = myvar

retrieve:
myvar = Session("myvar")

Better anyway always to check if Nothing in case expired

If myvar IsNot Nothing Then
'...
Else
'Inform user
End If

Tommaso

Ben ha scritto:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top