Groups | Blog | Home
all groups > vb.net controls > august 2006 >

vb.net controls : how to pass variable from one event to the other?


tommaso.gastaldi NO[at]SPAM uniroma1.it
8/19/2006 5:01:27 PM
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:

[quoted text, click to view]
Ben
8/19/2006 11:11:00 PM
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

Ben
8/20/2006 12:00:00 AM
Thanks

<tommaso.gastaldi@uniroma1.it> schreef in bericht
news:1156032087.137098.251600@h48g2000cwc.googlegroups.com...
[quoted text, click to view]

AddThis Social Bookmark Button