|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to pass variable from one event to the other?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 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: Show quoteHide quote > 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 Thanks
<tommaso.gasta***@uniroma1.it> schreef in bericht Show quoteHide quote news:1156032087.137098.251600@h48g2000cwc.googlegroups.com... > 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: > >> 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 > |
|||||||||||||||||||||||