| 代码说明:可以通过把一个子程序与事件关联来处理ASP.NET控件所产生的事件。
下面的代码,点击“Click here”按钮时,就执行btnSubmit_Click的子程序。显示"Hello World!".btnSubmit_Click子程序通过控件的OnClick方法与Button控件关联。
<Script Runat="Server">
Sub btnSubmit_Click( s As Object, e As EventArgs )
lblMessage.Text = "Hello World!"
End Sub
</Script>
<html>
<head><title>DisplayMessage.aspx</title></head>
<body>
Click on the button to view the message:
<form Runat="Server">
<asp:Button
id="btnSubmit"
Text="Click Here!"
OnClick="btnSubmit_Click"
Runat="Server" />
<p>
<asp:Label id="lblMessage" Runat="Server" />
</form>
</body>
</html>
|