开发者

retain value after page refresh

I am using a button control("validation button") in c#. I define some global variable in my project. when I clicked the button some form validation happens and an another button("save button") gets visible. the problem is when i click the validation button, the current page refreshes and the global variable doesn't contain the values. it shows nul开发者_Python百科l. how cal i maintain the value in global variable even after page refresh.


This is asp.net, correct?
Store this value in session Session["MyVariable"] = value and read it from session value = Session["MyVaraible"]
There other alternatives, ViewState, Application or even use a static variable but using session will be simple enough for you.


Its not clear what do you mean by global variable. Assuming that its page level (instance) variable, your best bet will be to use view-state. Define a view-state backed property such as

private int MyVar
{
  get
  {
     var value = ViewState["MyVar"];
     return null != value ? (int)value: 0;
  }
  set
  {
    ViewState["MyVar"] = value;
  }
}


I think you need to use Session State http://msdn.microsoft.com/en-us/library/87069683(v=vs.80).aspx


Second way: use client events of button without PostBack (set button AutoPostback property to false) to validate your form. After that use server handler of second button to post form fields values...


I think you mean that:you declared some variables globally , but normally those variables will lost their values at the end of the page cycle.

if you want to maintain the variables values after post back you can use static variables,but take care they will be shared between all users.the good choice using session variables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜