Thursday, March 22, 2012

Newbies Question on data variables

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? ThanksAre 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" <wkichu@.hotmail.comwrote in message
news:e69UdhWpGHA.4988@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

>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
>


Thanks. That's what I need.

"Eliyahu Goldin" <removemeegoldin@.monarchmed.comglsD:uVtA7 RYpGHA.4268@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

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" <wkichu@.hotmail.comwrote in message
news:e69UdhWpGHA.4988@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

>>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
>>


>
>

0 comments:

Post a Comment