Hi everybody,

In my web form, I have declared a form level variable - vabc. I am trying to retain the value of the variable after a postback using ViewState. Following is my code:

VB Code:
  1. Dim vabc as String
  2.  
  3.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         If Page.IsPostBack Then
  5.             vabc = ViewState("vabc")
  6.         Else
  7.             vabc = "vParty01"
  8.         End If
  9.     End Sub
  10.  
  11.     Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload
  12.         ViewState("vabc") = vabc
  13.     End Sub

However, after a postback the value stored in ViewState("vabc") is lost. Why is it not retaining the value? What is the solution?