[转]Dropdownlist doesn't postback after Page_ClientValidate()

本文转自:http://stackoverflow.com/questions/2083929/dropdownlist-doesnt-postback-after-page-clientvalidate

Update:

I have just found the solution. The following function works (remove the else part):

function confirmSubmit() { if (Page_ClientValidate("Group1")) { return window.confirm("Are you sure to submit the form?"); } }

But I am wondering why it doesn't work when I add the else part.

Question:

I want to have a confirm dialog after user fills in all the data in the form. I set onclientclick="return confirmSubmit()" in the submit button.

 function confirmSubmit() { if (Page_ClientValidate("Group1")) { return window.confirm("Are you sure to submit the form?"); } else { return false; } }

If Page_ClientValidate("Group1") returns false, the dropdownlist doesn't cause postback after I first select the item, and the postback only occurs when I select the dropdownlist second time.

What's the problem?

share improve this question
 
1  
Your validation rules are saying the page is invalid and causing the postback to stop...which is what they're supposed to do. Can you post the markup for your validators? One of them in Group1 is saying that it's not in a valid state. – Nick Craver Jan 18 '10 at 4:46
    
I have found the solution. – Billy Jan 18 '10 at 4:56

2 Answers

active oldest votes
up vote 8down vote

After Page_ClientValidate is called, the variable Page_BlockSubmit gets set to true, which blocks the autopost back. Page_BlockSubmit was getting reset to false on the second click, for what reasons I still don't fully understand. I'm looking more into this, but I have a solution and I'm under the gun so I'm rolling with it....

Just add below code in the code block which executes if Page is not valid.

Page_BlockSubmit = false;

e.g.

function ValidatePage() { flag = true; if (typeof (Page_ClientValidate) == 'function') { Page_ClientValidate(); } if (!Page_IsValid) { alert('All the * marked fields are mandatory.'); flag = false; Page_BlockSubmit = false; } else { flag = confirm('Are you sure you have filled the form completely? Click OK to confirm or CANCEL to edit this form.'); } return flag; }
share improve this answer

 

你可能感兴趣的:([转]Dropdownlist doesn't postback after Page_ClientValidate())