ASP.NET - C# passing a variable to the page with postback
-
Hi, I have a method that retrieves a variable with a click of a LinkButton. I need to use that variable in an other method but it becomes null for some reason. I guess that happens because of the page postback every time and since i have an initialization command at the beginning of my code it makes it null again. So should i pass an argument with the page postback or disable the linkbutton's postback. And How could i do any of those? Your help is greatly appreciated. phivos
-
Hi, I have a method that retrieves a variable with a click of a LinkButton. I need to use that variable in an other method but it becomes null for some reason. I guess that happens because of the page postback every time and since i have an initialization command at the beginning of my code it makes it null again. So should i pass an argument with the page postback or disable the linkbutton's postback. And How could i do any of those? Your help is greatly appreciated. phivos
Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback? Just wanted to make a note that I am a newbie and am trying to contribute to this site as others have helped me.
-
Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback? Just wanted to make a note that I am a newbie and am trying to contribute to this site as others have helped me.
ffowler wrote:
Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback?
Have to agree with you FFowler there hold the variable value in session or viewstate but could you elaborate on the sequence of events you are trying to implement?
-
ffowler wrote:
Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback?
Have to agree with you FFowler there hold the variable value in session or viewstate but could you elaborate on the sequence of events you are trying to implement?
-
ffowler wrote:
Not sure if you need this variable to persist, but if you do, couldn't you assign it to a Session Variable and retrive it whenever you do a postback?
Have to agree with you FFowler there hold the variable value in session or viewstate but could you elaborate on the sequence of events you are trying to implement?
Yes exactly, does any of you guys know how to assign it as a Session variable and then how to retrieve it back? Thanks a lot!
-
Yes exactly, does any of you guys know how to assign it as a Session variable and then how to retrieve it back? Thanks a lot!
Session["Giveitaname"] = value //if the value you are storing is string i suggest do this if(!string.IsNullorEmpty(Session["Giveitaname"].toString()) { newvalue = Session["Giveitaname"].tostring(); } //otherwise just check if null then cast it accordingly
-
Session["Giveitaname"] = value //if the value you are storing is string i suggest do this if(!string.IsNullorEmpty(Session["Giveitaname"].toString()) { newvalue = Session["Giveitaname"].tostring(); } //otherwise just check if null then cast it accordingly
Thank's a lot for your post! Works!