【问题标题】:Dropdownlist doesn't postback after Page_ClientValidate()下拉列表在 Page_ClientValidate() 之后不回发
【发布时间】:2010-01-18 04:37:30
【问题描述】:

更新:

我刚刚找到了解决方案。以下函数有效(删除 else 部分):

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

但我想知道为什么当我添加 else 部分时它不起作用。

问题:

我希望在用户填写表单中的所有数据后有一个确认对话框。 我在提交按钮中设置了 onclientclick="return confirmSubmit()"。

 function confirmSubmit() {

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

         return false;
     }
 }

如果Page_ClientValidate("Group1") 返回false,则下拉列表在我第一次选择项目后不会导致回发,并且只有在我第二次选择下拉列表时才会发生回发。

有什么问题?

【问题讨论】:

  • 您的验证规则说页面无效并导致回发停止......这是他们应该做的。你可以为你的验证者发布标记吗? Group1 中的其中一个说它不处于有效状态。

标签: asp.net


【解决方案1】:

调用 Page_ClientValidate 后,变量 Page_BlockSubmit 被设置为 true,这会阻止自动回发。 Page_BlockSubmit 在第二次点击时被重置为 false,我仍然不完全理解的原因。我正在对此进行更多研究,但我有一个解决方案,而且我在枪下,所以我正在努力......

只需在页面无效时执行的代码块中添加以下代码。

Page_BlockSubmit = false;

例如

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;       
}

【讨论】:

    【解决方案2】:

    我刚刚找到了解决方案。以下功能有效(删除 else 部分):

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多