(c) 2003 Visual Studio Magazine 
Fawcette Technical Publications

VB.NET	Maintain State During Postbacks
Listing 1	This code demonstrates how to use the ViewState collection. ASP.NET stores input form elements in ViewState for preserving them between postbacks. However, ASP.NET treats ViewState like any other key-value pair collection, so you can add your own values as your application requires.


Private Sub Page_Load(ByVal sender As _
	System.Object, ByVal e As System.EventArgs) _
	Handles MyBase.Load
	If Not Me.IsPostBack Then
		Me.ViewState.Add("salary", _
			Request.QueryString("salary"))
		Me.ViewState.Add("increases", 0)
	End If
End Sub

Private Sub cmdRaiseSalary_Click( _
	ByVal sender As System.Object, ByVal e As _
	System.EventArgs) Handles cmdRaiseSalary.Click
	Dim rSalary As Double = _
		CDbl(Me.ViewState("employeeSalary"))
	Dim iIncreaseCount As Integer = _
		CInt(Me.ViewState("increases"))
		iIncreaseCount += 1
		rSalary *= 1.01
	Me.ViewState("employeeSalary") = rSalary
	Me.ViewState("increases") = iIncreaseCount
End Sub
