| 代码说明:LinkButton控件呈现一个超文本链接外,同Button控件和ImageButton控件类似。当单击超文本链接时,包含该链接按钮的表单中所有的域都被提交到服务器。
下面的程序清单演示如何使用一个链接按钮提交表单,该页面随机显示你的运程,当你输入你的名字并单击链接按钮时,就执行LinkButton_Click子程序,并且随机显示四个运程之一.
<Script Runat="Server">
Sub LinkButton_Click( s As Object, e As EventArgs )
Dim RanNum As New Random
Select Case RanNum.Next( 4 )
Case 0
lblFortune.Text = txtUsername.Text & ", good things are coming!"
Case 1
lblFortune.Text = txtUsername.Text & ", you are doomed!"
Case 2
lblFortune.Text = txtUsername.Text & ", invest in Microsoft!"
Case 3
lblFortune.Text = txtUsername.Text & ", this book will change your life!"
End Select
End Sub
</Script>
<html>
<head><title>LinkButton.aspx</title></head>
<body>
<form Runat="Server">
Enter your name to receive your fortune:
<p>
<asp:TextBox
ID="txtUsername"
Runat="Server"/>
<p>
<asp:LinkButton
Text="Tell Me!"
OnClick="LinkButton_Click"
Runat="Server"/>
<hr>
<asp:Label
ID="lblFortune"
Runat="Server" />
</form>
</body>
</html>
|