Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textbox value changed

Is it possible to know if any of the textbox values have changed in the application. I have around 30 textboxes and I want to run a part of code only if, any of the textboxes value has changed out of the 30. Is there a way I can know that.

like image 786
developer Avatar asked Apr 06 '10 19:04

developer


People also ask

How to Check if TextBox value is changed in c#?

TextChanged += new EventHandler(this. TextWasChanged); txtBox. TextChanged += new EventHandler(this.

Which event is generated when TextBox text is changed?

The event handler is called whenever the contents of the TextBox control are changed, either by a user or programmatically. This event fires when the TextBox control is created and initially populated with text.

What is TextChanged in c#?

The TextChanged event is raised when the content of the text box changes between posts to the server. The event is only raised if the text is changed by the user; the event is not raised if the text is changed programmatically.


1 Answers

Each text box will raise an event TextChanged when it's contents have changed. However, that requires you to subscribe to each and every event.

The good news is that you can subscribe to the event with the same method multiple times. The handler has a parameter sender which you can use to determine which of your 30 text boxes has actually raised the event.

You can also use the GotFocus and LostFocus events to keep track of actual changes. You would need to store the original value on GotFocus and then compare to the current value on LostFocus. This gets round the problem of two TextChanged events cancelling each other out.

like image 155
ChrisF Avatar answered Oct 03 '22 20:10

ChrisF