asp.net - .net using and reaching public value -
i wrote code in .net. when want change ‘s’ clicking button2, doesn’t change. mean after clicking button2 , click button1 see changes nothing changes. how can change , access value of ‘s’ properly. doing wrong?
public string s; public void button1_click(object sender, eventargs e) { label1.text = s; } public void button2_click(object sender, eventargs e) { s = textbox1.text; }
you need understand how web applications work.
in each post instance of class handles page loaded, when click on button 1, page post , loads again, way variable s isn't loaded content.
to make code work, need save s values on page viewstate.
try replacing "public string s;" this:
public string s { { return (string)viewstate["myvalue"]; } set [ viewstate["myvalue"] = value }; }
more information page life cycle at: http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx
Comments
Post a Comment