views:

462

answers:

1

I have a web service that validates some form data. The service is a ScriptService, and I am calling it from the client. I need to display a modal popup if the validation fails. If the user clicks "OK" on the modal popup, then I want to post back and save my data. "Cancel" should allow them to close the modal popup and let the user correct data, allowing one to resubmit. Currently, the modal popup displays every time regardless of the result of the validation.

I tried calling hide() and returning false, but neither worked.

I tried approaching this problem from a different perspective by assigning the TargetControlID property of the modalpopupextender to a hidden button and then calling show() on the modal popup if validation failed, but this did not cancel the postback. The modalpopup displays for approximately one second and the page posts back.

+4  A: 

So you want to do something like:

function ValidateInput() {
   MyScriptService.ValidateInput({however you are passing form data}, OnValidateComplete);
}

function OnValidateComplete(response) {
   if ({response is bad}) {
      $find('<%= ModalPopupExtender.ClientID %>').show();
   }
}

You can then keep your TargetControlID, OnOkScript, etc. all the same. Perhaps with some code we can actually see what you are doing.

Cory Larson
Excellent response. It's almost like you've done this before :-)
Jose Basilio