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 null. how cal i maintain the value in global variable even after page refresh.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
This is asp.net, correct?
Store this value in session
Session["MyVariable"] = value
and read it from sessionvalue = 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
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 usingsession variables
.I think you need to use Session State http://msdn.microsoft.com/en-us/library/87069683(v=vs.80).aspx