简体   繁体   中英

how to convert viewstate to session state?

I have created the view state. i want to use the view state in different pages.Is is possible to access the view state in different pages?

else can move the view state in session object in asp.net c#. how to do that?

i want to use the view state in different pages

Answer: Then There is no Need to Use ViewState .You Should Use Session as Per Your Question

What is ViewState

View State is one of the most important and useful client side state management mechanism. It can store the page value at the time of post back (Sending and Receiving information from Server) of your page. ASP.NET pages provide the ViewState property as a built-in structure for automatically storing values between multiple requests for the same page.

What is Session

Session provides a facility to store information on server memory. It can support any type of object to store along with our own custom objects. For every client, session data is stored separately, which means session data is stored on a per client basis

You can Easily Convert Session to ViewState

if(Session["Key"]!=null)

Viewstate["Key"] = Session["Key"];

or Vice Versa

if(Viewstate["Key"]!=null)

Session["Key"]=Viewstate["Key"]

Viewstate is equal to hidden field value. This is available to current page only where viewstate is defined and used. If you want to read those data in other pages it won't be available.

You need to store those values to session ,wherever you have done ViewState["key"]= "value" . And you mean to access key in other pages. Viewstate is saved as encoded value in hidden field whereas session value is stored in server memory.

eg Session["key"] = "value" .

Session is used for multiple pages while viewstate can only be use to one page

How to convert session to viewstate.

Viewstate["ABC"] = Session["ABC"]

but for multiple pages you need session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM