validation – ASP.NET – UpdatePanel causes textbox to clear in UserControl – Education Career Blog

I have a Page, containing an UpdatePanel and a Usercontrol which loads another usercontrol, containing a textbox.

So it’s Page->UpdatePanel->UserControl->UserControl (B)->Textbox

The ValidationGroup for the button and textbox is the same. I call .validate(“answer”) in the codebehind, I’d rather not use the JS validation. If the button is clicked, the value in the textbox is cleared and the error displays, but only on the first click. After that it works fine, but then a different UserControl (B) with the same same setup. The same happens again, on the first click. If I fill in the value again, it stays and I get a postback.

This is bizarre and I can’t think what would cause it, if I add the button as a postbacktrigger (ie: remove the updatepanel), it works normally. I’ve tried setting CausesValidation on the button with no effect and I’m out of ideas.


Are you sure your not clearing the value of the textbox in your code somewhere?

Can you put up some code for us to take a look at?


This was actually caused by the ID of UseControl (B) changing between the first and subsequent postbacks. The ID needs to stay the same I think for the ViewState to populate back.

Leave a Comment