Using ViewState to pass variables

G

Guest

Hi,
would like to know whether I can use ViewState to pass variables from one
web page to another. I've been trying do this but all I managed to do is to
pass the variable to the target page but am unable to extract the variable
out to print on the page. The source of the target page reflects a ViewState
value being passed. My code is as below:
(On 1st page)
ViewState("name") = Name
Response.Redirect("targetpage.aspx")

(On targetpage.aspx)
Name: <% Response.Write(CStr(ViewState("name")))%>

(Source of targetpage.aspx)
<form name="_ct10" method="post" action="targetpage.aspx" id="_ct10">
<input type="hidden" name="__VIEWSTATE" value="some gibberish string" />

Anything wrong with my code or do I need to import additional namespace?

Rgds,
blurz
 
C

Cor Ligthert

Blurz,

Between pages, in a normal way, No.

Use a session.item (any other method is mostly a lot of work or/and not real
reliable)

I hope this helps,

Cor
 
G

Guest

Hi ,

As far as I could read on the ViewState is use to store in a hidded field on
a page.
In addition to that it is limited to item that can be serialized.
Asp.net handle ViewState content in hash data in order to avoid kind of
ackibg from server side.

If you want to keep track of variable during the life time of your
application its better and recomanded to use Application or Session object

Hope it helps
regards
serge
 

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

Top