不触发动态创建的按钮单击事件

编程入门 行业动态 更新时间:2024-10-19 02:16:17
本文介绍了不触发动态创建的按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好 iam在我的要求中动态创建按钮,并在Web应用程序上工作,当我单击按钮时,它基于按钮单击事件而工作. IAM创建一个动态按钮,但单击和命令事件未触发 这是我的代码...

hi all iam working on web application in my requirement creating dynamically button and when i click an button it''s worked based on button click event. Iam creating a dynamically button but click and command event not firing here my code is............

public partial class Default11 : System.Web.UI.Page { private Button BtnServices; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } protected void Button1_Click(object sender, EventArgs e) { BtnServices = new Button(); BtnServices.ID = "BtnServices"; BtnServices.Text = "Click Me"; BtnServices.Click += new EventHandler(BtnServices_Click); BtnServices.Command += new CommandEventHandler(BtnServices_Command); form1.Controls.Add(BtnServices); } void BtnServices_Click(object sender, EventArgs e) { Response.Write("hi"); } void BtnServices_Command(object sender, CommandEventArgs e) { Response.Write("hi"); } }

点击事件和命令事件不会触发. 让我知道我做错了吗? 在此先感谢.........

here click event and command event not firing. let me know were i went wrong? thanks in advance.........

推荐答案

检查此 Hi , Check this private Button BtnServices; protected void Page_Load(object sender, EventArgs e) { if (ViewState["falg"] != null) { Create(); } } protected void Button1_Click(object sender, EventArgs e) { Create(); ViewState.Add("falg", true); } void BtnServices_Click(object sender, EventArgs e) { Response.Write("hi"); } void BtnServices_Command(object sender, CommandEventArgs e) { Response.Write("hi"); } void Create() { BtnServices = new Button(); BtnServices.ID = "BtnServices"; BtnServices.Text = "Click Me"; BtnServices.Click += new EventHandler(BtnServices_Click); BtnServices.Command += new CommandEventHandler(BtnServices_Command); form1.Controls.Add(BtnServices); }

最好的问候 M.Mitwalli

Best Regards M.Mitwalli

您的问题已经在不动态触发按钮单击事件 [ ^ ] Your question is already answered at not firing button click event dynamically[^]

更多推荐

不触发动态创建的按钮单击事件

本文发布于:2023-11-02 14:24:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552653.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   按钮   事件   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!