当前位置:主页 > 软件编程 > .NET代码 >

C#动态生成按钮及定义按钮事件的方法

时间:2021-10-18 10:05:30 | 栏目:.NET代码 | 点击:

本文实例讲述了C#动态生成按钮及定义按钮事件的方法。分享给大家供大家参考。具体实现方法如下:

1、后台生成input的button按钮

复制代码 代码如下:
HtmlGenericControl control = new HtmlGenericControl("input");
control.Attributes.Add("type", "button");
control.Attributes.Add("onclick",Page.ClientScript.GetPostBackEventReference(this, "btnMyQuery")

写入到界面中

2、后台回发拦截与处理

if (Page.IsPostBack)
{
 //获得回发参数
 string eventArgument = Page.Request.Form["__EVENTARGUMENT"];
 if (!String.IsNullOrEmpty(eventArgument)
   && eventArgument.Equals("btnMyQuery"))
 {
   //执行您的回发处理代码
 }
}

希望本文所述对大家的C#程序设计有所帮助。

您可能感兴趣的文章:

相关文章