c# - Session variable can't be updated -


whenever try update session variable has been entered won't update.

heres example on i'm talking about:

protected void page_load(object sender, eventargs e) {     if (session["test"] != null)      {         textbox1.text = session["test"].tostring();     } } protected void button1_click(object sender, eventargs e) {     session["test"] = textbox1.text; } 

so when click button first time, textbox updated. when edit text , click button again, textbox reverts first time i.e doesn't update. have ideas?

so when click button first time, textbox updated. when edit text , click button again, textbox reverts first time

i believe it's because doing that:

protected void page_load(object sender, eventargs e) {     if (session["test"] != null)      {         textbox1.text = session["test"].tostring();     } } 

in code have should checking if page load caused post (click of button). should doing this:

protected void page_load(object sender, eventargs e) {     if (!ispostback && session["test"] != null)      {         textbox1.text = session["test"].tostring();     } } 

Comments