zoukankan      html  css  js  c++  java
  • [转]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
  • 相关阅读:
    3步学会用gulp
    div需要重置吗?
    HTML元素遮挡Flash之梦
    移动WEB开发常用技巧
    四:分组查询
    三:函数
    二:查询
    一:MySQL
    三:JVM(重点)
    二:JAVA通知唤醒机制,Lock替换synchronize
  • 原文地址:https://www.cnblogs.com/freeliver54/p/5630866.html
Copyright © 2011-2022 走看看