c# - how to avoid re initialization of session value after redirecting to same page -


i have intialized session variables in page load method zero. modifying them in button press method. using 1 session variable counter when redirecting page same page, variables intialized again. please me prevent re-initialization. i don't want use static variables.

the scenario is-

protected void page_load(object sender, eventargs e) {     session["counter"] = 0; } protected void button1_click(object sender, eventargs e) {     int count = (int)session["counter"];     count++;     session["counter"] = count;     response.redirect("same page"); } 

assuming want check non set session variable , if so, set zero, do:

protected void page_load(object sender, eventargs e)  {       if(session["counter"] == null) {           session["counter"] = 0;       }  } 

there range of client side options use, depending on situation.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -