I have a basic form with some ASP.NET textbox fields laid out and I also have created a control extender which after a change event on a seperate textbox occurs it sets a certain set of textboxes values to blank.
The form I have is a user control which exposes public properties to retrieve the values of the TextBoxs. When the form is submitted and I access the properties, the original values when the page was loaded are coming back instead of the blank or null value. Can someone explain to me why this is happening.
I have a page with the control on it, that control has the textboxs and the properties to expose the textbox values. After client events the populated textboxes are set to blanks. When I submit the form (submit button is on the control, but an event is exposed that I wire up on the parent form) I try to access the controls properties but they contain the original values.
I think this has something to do with the state bag but am not sure.
Any help would be great.
Thank You.
When you change values using ajax/jquery or anything client side the new values don’t interact with the ViewState. Therefore when the page reloads the original values are restored from the ViewState wiping out anything that has happen via ajax.
This is a fault/feature of the asp.net postback model. I believe it is why the MVC framework has become popular – it doesn’t have postbacks or viewstate at all so plays a lot nicer with AJAX.
I have got AJAX to work and persist with postbacks but it’s a pain. I did the following
It’s what I did – there might well be a better answer/work around.
In short – postbacks destroy AJAX