简体   繁体   English

如何动态触发动态创建的文本框的事件?

[英]How can I dynamically fire an event for a textbox which is dynamically created?

How can I dynamically fire an event for a textbox which is dynamically created? 如何动态触发动态创建的文本框的事件? I have used this code: 我使用了以下代码:

lab.Click += new EventHandler(lab1_Click);

But this code is not working... 但是这段代码不起作用...

Dynamically created controls have to be re added to page control hirearchy in the Page_Init event with the same ID with which you added it last them. 必须将动态创建的控件重新添加到Page_Init事件中的页面控件级别中,并使用与您最后添加的ID相同的ID

Then only the ASP.NET framework will match the post back data (which in your case will have data for TextChange) and hook control and the event to its event handler. 然后只有ASP.NET框架将匹配回发数据(在您的情况下,该数据将具有TextChange的数据),并将控件和事件挂钩到其事件处理程序。 Else nothings gona happen 其他什么都没发生

Check this article for details 查看本文以了解详细信息

http://support.microsoft.com/kb/317515 http://support.microsoft.com/kb/317515

.net did not allow the Click Event over Text box. .net不允许在文本上单击事件框。 If you want that event fires when textbox loses the focus, you can use "lab_validate()" event. 如果希望在文本框失去焦点时触发该事件,则可以使用“ lab_validate()”事件。

There are many other events for TextBox choose what you feel suitable. TextBox还有许多其他事件可以选择您认为合适的事件。

lab.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM