Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: maintain global variable value during postback with viewstate


Message #1 by "John Tyson" <jtyson@t...> on Tue, 25 Mar 2003 19:03:00 -0800
Hi,

I have not worked with maintaining values through postback with
viewstate.  I have an aspx page which does the following (abbreviated):

<script language=3D"VB" runat=3D"server">
   Dim strClinID As String =3D Nothing
  
   Sub Page_Load(s As Object, e As EventArgs)
      If Not Page.IsPostBack Then
         ...Call to my stored proc, return parameters
         strClinID =3D cmd.Parameters("@clinicID").Value
      End If
  End Sub

  Sub InsPlan_Changed(s As Object, e As EventArgs)
     ...I want strClinID to be available here, with the value assigned
in the pageload event above

Basically I want to assign a value to the global variable strClinID in
my pageload and then persist it through postbacks so that it is
available to the rest of my subroutines.

I have received suggestion to use this code but am not sure how to apply
it to the above:

Public Property Myvar() As Integer
   Get
      Dim savedValue As Object =3D MyBase.ViewState("MyVar")
	If Not IsNothing( savedValue ) Then
		Return Ctype(savedValue, Integer)
	End If
	Return 0 'Or whatever you want the default to be
   End Get
   Set(ByVal Value As Integer)
      MyBase.ViewState("MyVar") =3D Value
   End Set
End Property

If someone would be generous enough to show me how to apply this with my
code above I would be greatful.  I am in quite a bit of a time crunch
and have not done anything like this before, and an example would go a
long way.

Thank you,

John

  Return to Index