Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropdownlist doesn't postback after Page_ClientValidate()

Tags:

asp.net

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?

like image 651
Billy Avatar asked Jan 18 '10 04:01

Billy


1 Answers

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;       
}
like image 81
Himalaya Garg Avatar answered Nov 15 '22 02:11

Himalaya Garg