Newbies Question on data variables

  • Thread starter Thread starter Vivian
  • Start date Start date
V

Vivian

I have an aspx page with C# with several "post" button. Each button will do
sth, and return some data to the same page. The problem is I have a public
variable, say tmpA in C# in which data will set while the first button is
clicked. I need to get the value of tmpA when pressing other button, the
problem is how can I save the value of tmpA?
Do I need to add a hidden field on the form to do that?
Or is there any better approach? Thanks
 
Are you asking how to preserve variables between postbacks? If this is what
you mean, put them in the VewState:

int tempA;
....
ViewState["TEMPA"] = tempA;
....
tempA = (int)ViewState["TEMPA"];
 
Thanks. That's what I need.

Eliyahu Goldin said:
Are you asking how to preserve variables between postbacks? If this is
what you mean, put them in the VewState:

int tempA;
...
ViewState["TEMPA"] = tempA;
...
tempA = (int)ViewState["TEMPA"];
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Vivian said:
I have an aspx page with C# with several "post" button. Each button will
do sth, and return some data to the same page. The problem is I have a
public variable, say tmpA in C# in which data will set while the first
button is clicked. I need to get the value of tmpA when pressing other
button, the problem is how can I save the value of tmpA?
Do I need to add a hidden field on the form to do that?
Or is there any better approach? Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top