Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Saving data between postbacks in the ViewState collection

Total Hit ( 2558)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


In classic ASP, the only way to preserve information - for example, the value of a variable- - between consecutive client requests is by means of Session variables, cookies, or other awkward techniques, such as arguments on the query string or values in hidden fields.

ASP.NET gives you yet another method, in the form of the ViewState property of the Page object. (More precisely, this is a protected property that the Page class inherits from the Control class.) This property represents the contents of the __VIEWSTATE hidden field and works as a StateBag dictionary of key-value pairs. The following example uses the ViewState property to preserve the number of requests to the current page:

Click here to copy the following block
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles _
  MyBase.Load

  ' Number of requests to this page posted so far.
  Dim count As Integer
  If Not Me.ViewState("count") Is Nothing Then
    count = CInt(Me.ViewState("count")) + 1
  End If
  ' Store the value back in the ViewState dictionary.
  Me.ViewState("count") = count
  ' Display in a Label control.
  lblCount.Text = count.ToString
End Sub

Keep in mind that this property works only if you left the EnableViewState property set to True.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.