I am removing the orignal event handler before adding a new event handler so there shouldn;t be multiple handlers for each instance.
else if (ControlType == "DropDown") { ... field_dropbox.SelectedIndexChanged -= new EventHandler(field_dropbox_SelectedIndexChanged); field_dropbox.SelectedIndexChanged += new EventHandler(field_dropbox_SelectedIndexChanged); ...
In the above, I don't understand why you are removing the event handler and then adding the same event handler right back...
If you want to stop the handler from processing when you are programmatically changing the item that causes the event to fire again, you can set a variable that indicates you are doing just that:
bool bInSelectedChangedEvent = false;
protected void field_dropbox_SelectedIndexChanged(Object sender, EventArgs e)
{
if (!bInSelectedChangedEvent)
{
// set flag to true to prevent processing while we are changing the item that causes the event to fire again...
bInSelectedChangedEvent = true;
// all the processing code in here...
}
bInSelectedChangedEvent = false;
}
However, you might have a design problem if you are modifying another control that is tied to the same event handler, which could then modify another control that is tied to the same event handler, which could then modify another control that is tied to the same event handler, which could then....etc. etc. etc.Is there a way to purge the eventhandler after it is fired so it does not fire if I make a subsequent change?
Not sure what you mean by purge, but if you can't use the recommendation above and you want to remove all event handlers associated with the control's event, just assign it null:
comboBox1.SelectedIndexChanged = null;
The above null assignment will remove all event handlers from that event member.