My application in C#
has a Textbox
with a txt_TextChanged
event.
private void txt_TextChanged(object sender, EventArgs e)
{
//Do somthin
}
But there's one specific part that I want to change txt.Text
without firing the txt_TextChanged
event.
txt.Text ="somthing" //Don't fire txt_TextChanged
How can I do that?
You can extend text box and introduce there a new property that will not trigger the TextChanged event.
try this extension method
you can use textbox.SetText("...") to change text and the TextChanged event will not be fired.
There is no direct way to prevent the raising of events for the text property, however your event handler can use a flag to determine weather or not to perform a task. This i likely to be more efficient than attaching and detaching the event handler. This can be done by a variable within the page or even a specialized class wrapper
With a variable:
With specialized event handler wrapper
A quick and dirty way is to do an
and then in the OnChange event, encapsulate the offending code with a