| 代码说明: 当AutoPostBac的值为True时,只要文本框的内容发生改变,包含文本框的表单就会自动提交.
下面的程序清单使用AutoPostBack属性来创建一个简单的游戏.要在游戏中获胜,必须在三个文本框中输入Apple.
<Script Runat="Server">
Sub ChangeBox1( s As Object, e As EventArgs )
txtBox1.Text = strReverse( txtBox1.Text )
CheckWin
End Sub
Sub changeBox3( s As Object, e As EventArgs )
txtBox3.Text = strReverse( txtBox3.Text )
CheckWin
End Sub
Sub CheckWin
If txtBox1.Text = "Apple" _
And txtBox2.Text="Apple" _
And txtBox3.Text="Apple" Then
lblMessage.Text = "You Win!"
End If
End Sub
</Script>
<html>
<head><title>TextboxAutoPostBack.aspx</title></head>
<body>
<form Runat="Server">
Enter the word Apple into all three TextBoxes:<p>
<asp:TextBox
ID="txtBox1"
AutoPostBack="True"
onTextChanged="ChangeBox3"
Runat="Server"/><p>
<asp:TextBox
ID="txtBox2"
AutoPostBack="True"
OnTextChanged="ChangeBox1"
Runat="Server"/><p>
<asp:TextBox
ID="txtBox3"
AutoPostBack="True"
OnTextChanged="ChangeBox3"
Runat="Server"/><p>
<asp:Label
ID="lblMessage"
Runat="Server" />
</form>
</body>
</html>
|