Surya sasidhar
Surya sasidhar

Reputation: 30303

ViewState in asp.net?

In a web application, I create a viewstate to maintain the value of variable within the page only, can I have anything like viewstate in WinForms, to maintain the values within the forms?

Upvotes: 0

Views: 1077

Answers (5)

Vano Maisuradze
Vano Maisuradze

Reputation: 5899

In windows foms, there is no need to save values in viewstate or sessions. See the link

But if you want to maintain values between asp.net forms, you can use Sessions

Upvotes: 0

Graham Clark
Graham Clark

Reputation: 12966

ViewState exists to get around the fact that websites use HTTP, a stateless protocol. In order to give the illusion of state, a load of encoded data is sent to the client, and back to the server on every POST. This is ViewState.

Windows Forms programs have state, it's a process that's running for as long as the program is open. So you can just use member variables in your form classes.

Upvotes: 1

Gopher
Gopher

Reputation: 927

As you applicaition is stateful, you can store data as you like - in-memory collections, fields of classes, files, xml, db. Viewstate intended to store data between postbacks, and there is no postbacks in winforms app.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

You don't really need viewstate in Windows Forms because you can store state for example in your main window class using public properties. And as long as your main form lives (which normally is the lifetime of the application) the state will be preserved. If you need to persist the state after the application closes you could store it in files or database.

ViewState is required in ASP.NET because the ASP.NET Form is destroyed after each request and you cannot store instance variables in it. You could use static members but then you get problems as static members are shared among all users of this ASP.NET application.

Upvotes: 4

Prabhavith
Prabhavith

Reputation: 486

You can serialize those values using XML or Database

Upvotes: 0

Related Questions