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

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

 中国搜首页 >>ASP.NET相关>>事件参数Object和EventArgs的含义 C#版

代码说明:事件中Object参数确定触发子程序的特定对象,并由此作出反应。下面的代码包含两个Button控件,绑定到了同样的子程序。即使两个按钮与同样的子程序关联,点击不同的按钮也。会具有不同的效果。子程序通过检查对象的ID的来查明哪个按钮被点击了。第二个参数EventArgs,该参数包含所产生事件的特定信息。在使用Button控件时,EventArgs参数没有任何属性。

<Script Runat="Server">
Sub Button_Click( s As Object, e As EventArgs )
If s.id = "btnHello" Then
lblMessage.Text = "Hello!"
Else
lblMessage.Text = "Goodbye!"
End If
End Sub
</Script>

<html>
<head><title>HelloGoodbye.aspx</title></head>
<body>
Click on the button to view the message:
<form Runat="Server">
<asp:button
id="btnHello"
Text="Say Hello!"
OnClick="Button_Click"
Runat="Server" />

<asp:button
id="btnGoodbye"
Text="Say Goodbye!"
OnClick="Button_Click"
Runat="Server" />
<p>
<asp:Label id="lblMessage" Runat="Server" />
</form>
</body>
</html>

   运行演示程序   

  ©2004   www.zhonguosou.com