Slow WebTextField TextChanged event

Is it normal to see the TextChanged event be very slow in firing. I have a text field in which I want to set a modified flag when it is modified by the user in order to avoid a an exchange with the server when the form is saved if the fields has not been modified. If I change the field text and immediately click the Save button I can often beat the TextChanged event from firing. As a result the modification does not get saved.

I was expecting the event to fire on each key stroke, I see that it waits a few ticks, I am guessing to prevent it from firing unecessarily too many times in succession.

I am trying to work around this by putting the save code in a timer, but so far that does not seem to help…

The event is delayed a few milliseconds for a smaller number of server requests.

So also do checks in but to action event.

Not sure what you meant. I think you mean to check if the text was modified in the action event as well. Is there any built in function to check if a text field has been modified besides storing the original text in a variable to check in the save button’s action event?

Even the text changed event tells you that.
You need to store old text and compare later.

Do checks both in textchanged event and action events to decide if user can proceed.

[quote=209783:@John Baughman]Is it normal to see the TextChanged event be very slow in firing. I have a text field in which I want to set a modified flag when it is modified by the user in order to avoid a an exchange with the server when the form is saved if the fields has not been modified. If I change the field text and immediately click the Save button I can often beat the TextChanged event from firing. As a result the modification does not get saved.

I was expecting the event to fire on each key stroke, I see that it waits a few ticks, I am guessing to prevent it from firing unecessarily too many times in succession.

I am trying to work around this by putting the save code in a timer, but so far that does not seem to help…[/quote]

From what you describe, you are trying to get a dirty state for the WebTextField. Why not use KeyPressed to set up a dirty as boolean property. Chances are it will have a lot less lag, since all it does is to look at one character and not the full content.

Additionally, in case a user pastes text into the field without the keyboard, you could keep a copy of the original content, and just before save, compare with the actual content. That would also prevent the issue of text not being saved you report.

This is more event traffic then it’s worth. I would go with Michel’s second suggestion. (Edit: just realized Christian suggested the same thing.)

Subclass WebTextField and make a version whereby the initially displayed value is retained in a property (i.e. OriginalText). When the user clicks Save loop through all the text fields on the page and call a subclass method which compares .Text and .OriginalText. The ones that are different will mark themselves as modified. Then your save routine can transmit only the modified data to the back end.

This avoids the timing issues you’re experiencing, the constant event transmissions back to the server, and it should handle all cases (typing; pasting; voice recognition; whatever).

Thanks to all for your suggestions. I think the best suggestion was to just bite the bullet and retain the newly displayed datat in properties and check for changes in the Save button’s action event. That is what I have done and in this particular case there are only a few fields. I think going forward I will create a single dictionary property to hold the original values for all the fields on the form. I think this will be much easier than creating individual properties for all the fields on the form.

The easiest would be to subclass TextField and add a boolean dirty, plus an OriginalText. Then you would have that for each new TextField without additional programmation.