Thursday, August 7, 2008

TextChanged event and ViewState

If you're coming from the word of traditional forms where the page containing form fields contains plain HTML and posts to a server-side script, you probably know that the textbox doesn't need ViewState to post data to the page.

However, you do need ViewState for the TextBox to properly track changes to the textbox value. This effects how the TextChanged event is fired for the textbox.

When ViewState is enabled:
The TextChanged event is fired when a change to the value is followed by a postback. Subsequent postbacks do not cause the event to fire.

When ViewState is disabled:
The TextChanged event is fired on all postbacks if the value is changed from it's initial value (such as the value set with the Text property).

No comments: