<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Hidden Fields and ViewState</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
<asp:Button ID="Button1" Runat="server" Text="Button" />
<asp:HiddenField ID="HiddenField1" Runat="server" />
</div>
</form>
</body>
</html>
File: Default.aspx.vb
<Serializable()> _
Public Class Person
Public firstName As String
Public lastName As String
End Class
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
If Not Page.IsPostBack Then
HiddenField1.Value = "foo"
ViewState("AnotherHiddenValue") = "bar"
Dim p As New Person
p.firstName = "Scott"
p.lastName = "Hanselman"
ViewState("HiddenPerson") = p
End If
End Sub
End Class
|