Viewing source for recipe0704vb.aspx

<%@ Page %>
<script language="vb" runat="server">
Sub Page_PreRender(sender As Object, e As EventArgs)
	If Not ViewState("UserName") Is Nothing Then
		UserNameLabel.Text = ViewState("UserName")
	End If
End Sub

Sub SaveButton_Click(sender As Object, e As EventArgs)
	ViewState("UserName") = UserNameTextBox.Text
End Sub
</script>
<html>
	<body>
		<form id="Recipe0702cs" method="post" runat="server">
			<P>
				Update UserName in ViewState:
				<asp:TextBox id="UserNameTextBox" runat="server"></asp:TextBox>
				<asp:Button id="SaveButton" runat="server" Text="Save" OnClick="SaveButton_Click"></asp:Button></P>
			<P>
				Current ViewState Contents:
				<br>
				<asp:Label ID="UserNameLabel" Runat="server" EnableViewState="False"></asp:Label>
				<br>
				<asp:Button id="RefreshButton" runat="server" Text="Refresh Without Saving"></asp:Button>
				<br>
				<a href="recipe0704vb.aspx">This Page - no PostBack</a> - ViewState does not persist.<br/>
				<a href="recipe0704cs.aspx">C# Version - same session</a> - ViewState does not persist.
			</P>
		</form>
	</body>
</html>