Friday, March 16, 2012

Passing a value to another page

When you are passing a value to another page, and will need access to it
throughout the page and on any postbacks, what is the best way to store
it? By making it a variable accessible to the whole page, or by putting
it in the ViewState?
Thanks,
Mike
*** Sent via Developersdex http://www.examnotes.net ***Store it in the ViewState. Keeping in a page-wide variable will not get the
value on postbacks.
"Mike P" wrote:

> When you are passing a value to another page, and will need access to it
> throughout the page and on any postbacks, what is the best way to store
> it? By making it a variable accessible to the whole page, or by putting
> it in the ViewState?
>
> Thanks,
> Mike
>
> *** Sent via Developersdex http://www.examnotes.net ***
>
Hi Mike,
In .NET 1.0/1.1 you can choose between QueryString, Session or
Server.Transfer. I recommend Session (it's just a matter of taste). In .NET
2.0 you use the PostBackUrl property on your controls. By setting the
PostBackUrl="/My2Page.aspx" in your Button tag the user will, when clicked,
be redirected to the My2Page.aspx in which you can access your values using
Request.Form.
Best regards,
Paul Gielens
Visit my blog @. http://weblogs.asp.net/pgielens/
###
"Mike P" <mike.parr@.gmail.com> wrote in message
news:etAmXpN9FHA.2036@.TK2MSFTNGP14.phx.gbl...
> When you are passing a value to another page, and will need access to it
> throughout the page and on any postbacks, what is the best way to store
> it? By making it a variable accessible to the whole page, or by putting
> it in the ViewState?
>
> Thanks,
> Mike
>
> *** Sent via Developersdex http://www.examnotes.net ***
>

0 comments:

Post a Comment