0

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?

Ofer Zelig
  • 17,068
  • 9
  • 59
  • 93
Surya sasidhar
  • 29,607
  • 57
  • 139
  • 219
  • What are you going to use this for? Your description sounds like you think this might be a solution, but if you tell us what you're looking for a solution to, we can help better. – Mr Lister Mar 27 '12 at 11:55

5 Answers5

4

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

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.

Graham Clark
  • 12,886
  • 8
  • 50
  • 82
0

You can serialize those values using XML or Database

Prabhavith
  • 458
  • 1
  • 4
  • 15
0

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.

Gopher
  • 917
  • 6
  • 18
0

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

Community
  • 1
  • 1
Vano Maisuradze
  • 5,829
  • 6
  • 45
  • 73