Removing an event handler from your code

I have an dropdown like this

<asp:DropDownList ID="ddLevel" runat="server" Width="95%" AutoPostBack="True" OnSelectedIndexChanged="ddYear_SelectedIndexChanged">


In some conditions, I am trying to remove the handler for the OnSelectedIndexChanged event. I tried

ddLevel.SelectedIndexChanged -=ddYear_SelectedIndexChanged;


It didn't work. Then I tried

ddLevel.SelectedIndexChanged -=new EventHandler(ddYear_SelectedIndexChanged);


But both of them don't work. When I check the page source, I still see the exchange event.

I have checked these two links link1 and link2 . I don't understand what I am doing wrong. I would like to knwo if there is another way to do this. Is the reason for this that I am doing this in an event Page_Load



source to share

1 answer

Below is to unsubscribe from the event, make sure that execution after this event did not happen in the event subscription page_load


ddLevel.SelectedIndexChanged -=ddYear_SelectedIndexChanged;




All Articles