中国搜 程序源代码学习 编程源代码 直接应用在编程实践中 优秀编程书籍源码欣赏

收藏本页到>> 新浪ViVi  365Key网摘   IE收藏夹 |设为首页

 中国搜首页 >>ASP.NET相关>>TextBox的AutoPostBack属性 C#版

代码说明: 当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>

   运行演示程序   

  ©2004   www.zhonguosou.com