在ASP.Net中定义了OnClick之类的事件,那么,如何从事件中反过来捕获到出发事件的对象呢,比如,在如下的函数button_click中输出触发者的ID值。
protected void testCommand(object sender, CommandEventArgs e)
{
Response.Write("<br>从Button的Command事件中捕获的参数:<br>commandArgument:" + e.CommandArgument + "<br>commandName:" + e.CommandName);
}
protected void button_click(object sender, EventArgs e)
{
Response.Write("Button点击事件的函数触发");
}
.....
<asp:Button ID="Button1" runat="server" CommandArgument="theCommandArgument" CommandName="theCommandName"
OnClick="button_click" OnCommand="testCommand" Text="Button" />
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="linkButton.CommandArgument"
CommandName="linkButton.CommandName" OnClick="button_click" OnCommand="testCommand">LinkButton</asp:LinkButton>
protected void testCommand(object sender, CommandEventArgs e)
{
Response.Write("<br>从Button的Command事件中捕获的参数:<br>commandArgument:" + e.CommandArgument + "<br>commandName:" + e.CommandName);
}
protected void button_click(object sender, EventArgs e)
{
Response.Write("Button点击事件的函数触发");
}
.....
<asp:Button ID="Button1" runat="server" CommandArgument="theCommandArgument" CommandName="theCommandName"
OnClick="button_click" OnCommand="testCommand" Text="Button" />
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="linkButton.CommandArgument"
CommandName="linkButton.CommandName" OnClick="button_click" OnCommand="testCommand">LinkButton</asp:LinkButton>
解决方案 »
- C#模拟登陆的POST难题急等高手帮忙
- 关于Microsoft.Win32.Registry.LocalMachine.OpenSubKey的问题
- 如何判断子串在父串中是否存在?
- Entity framework4.1如何手动添加导航属性
- 急用!!!C#与VC数据类型转换问题---------请高人指点
- c# winform的colorDialog如何获取选中的颜色值,最好是八位十六进制的数字形式。
- 请问C#可以做自动测试工具嘛?该如何做呢?
- C#自定义控件时 用了onpaint事件重绘 ,但是却没有实时
- 关于目录递归调用的问题?
- 在C#中,如何检查Access2000表中的一个字段是否存在?
- 典型白吃问题Winform窗体的问题!
- 高分 求帮忙 很简单的 但绝对不是大问题 50分送上
protected void button_click(object sender, EventArgs e)
{
Button ctl=sender as Button;
if (ctl != null)
{
Response.Write("觸發事件的對象ID為:{0}",ctl.ID);
}
}