Click here to Skip to main content
15,909,437 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
hi,assume there are 2 TextBox on the form. textbox2 can get value by user or on code behind. if user fill textbox1,textbox2 will got value automatically from code behind.
now if user change textbox2 manually,it's value should get manually value .
I wrote a code on Textbox1_Leave that initiate textbox2 automatically,I want disable this event in Texbox2_KeyPress when user changed Texbox2 Text manually.thanks all.
Posted
Comments
BillWoodruff 3-Feb-14 21:58pm    
You mention "code behind:" if this is ASP.NET then please tag your question to indicate that.

1 solution

The easy way:
use a (class-) global status variable of type boolean.
Set this variable to true when you do not want the other event fired.
In Textbox1_Leave check this variable. If true, just return.

This would look like this
C#
private bool _noEvent = false;

protected Texbox2_KeyPress(object sender)
{
  _noEvent = true;

  // ... your other code
}

protected void Textbox1_Leave(object sender)
{
  if(_noEvent)
    return;
  
  // ... your other code
}
 
Share this answer
 
Comments
BillWoodruff 3-Feb-14 22:34pm    
+5 Good answer !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900