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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转]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?

shareimprove 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

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;       
}
shareimprove this answer

 

以上是关于[转]Dropdownlist doesn't postback after Page_ClientValidate()的主要内容,如果未能解决你的问题,请参考以下文章

javascript 怎么获取dropdownlist上的值,

asp.net里的关于dropdownlist控件的问题!

'mysql.column_stats' doesn't exist and Table 'mysql.index_stats' doesn't exi

Bug? #1146 - Table 'xxx.xxxxx' doesn't exist

hibernate-Table 'XXX.XXX' doesn't exist

mysql 提示table doesn't exist