开发者

Remove asp.net event on code behind

I want to remove an event in code behind.

For example my control is like this.

<asp:Textbox ID="txtName" runat="server" OnTextChanged="txtName_Changed" AutoPostBack="true" />

I want to remove the OnTe开发者_运维百科xtChanged programmatically.. how can I achieve this?


In C#, you can add and remove event handlers quite easily from the code-behind:

// Add event handler:
txtName.OnTextChanged += new EventHandler(txtName_Changed);

// Remove event handler:
txtName.OnTextChanged -= new EventHandler(txtName_Changed);


In VB.NET code:

RemoveHandler txtName.OnTextChanged, addressof txtName_Changed

Or in C#:

http://www.devnewsgroups.net/dotnetframework/t16784-remove-event-handlers-net.aspx

obj.Click += new EventHandler(BeAlert); // register an event handler
obj.Click -= new EventHandler(BeAlert); // unregister the same event handler
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜