Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove asp.net event on code behind

Tags:

c#

asp.net

events

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 OnTextChanged programmatically.. how can I achieve this?

like image 906
rob waminal Avatar asked Mar 01 '11 08:03

rob waminal


People also ask

How do you set display none in code behind?

Add("style","display:none"); div_id: id which you want to hide. Attributes: that will use value. Add: keyword will add the attribute.


2 Answers

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);
like image 158
FarligOpptreden Avatar answered Sep 28 '22 00:09

FarligOpptreden


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
like image 44
Rhapsody Avatar answered Sep 28 '22 00:09

Rhapsody