简体   繁体   English

为什么我的表单在验证后不会发回?

[英]Why won't my form post back after validation?

I have an asp.net page with multiple validation summaries setup with ShowMessageBox="True" and several validators. 我有一个asp.net页面,其中包含使用ShowMessageBox="True"和几个验证器设置的多个验证摘要。 I have run into a situation where when validation fails the validation summary displays correctly but then the next click that would normally trigger a postback of the page does not trigger a postback. 我遇到了一种情况,当验证失败时,验证摘要会正确显示,但是通常会触发页面回发的下一次点击不会触发回发。 So the steps look like this: 所以步骤看起来像这样:

  1. Click button that triggers validation. 单击触发验证的按钮。
  2. Validation fails and a messagebox with the failure message is displayed. 验证失败,并显示带有失败消息的消息框。
  3. Click a different button which does not validate but should trigger a postback nothing happens 单击另一个不验证的按钮但应该触发回发没有任何反应
  4. Click same button as step 3 again postback happens as expected. 再次单击与步骤3相同的按钮,回发按预期发生。

What could cause this behavior? 什么可能导致这种行为?

EDIT: The validation was being done in the following manner. 编辑:验证是按以下方式进行的。 In the asp page: 在asp页面中:

<asp:Button runat="server" id="btn" onClientClick="return DoValidation();" />

In the javascript: 在javascript中:

function DoValidation() {
    if (!Page_ClientValidate('group1'))
        return false;
    if (!Page_ClientValidate('group2'))
        return false;

    return true;
}

After working on this and making careful use of the debugger I finally found out that when you do validation the way described in the edit to the question a boolean is set on failure that blocks the next PostBack of the page from going through. 在对此进行了处理并仔细使用调试器之后,我终于发现,当您按照编辑问题中描述的方式进行验证时,布尔值设置为失败,阻止页面的下一个PostBack通过。 I believe this is done when validation is being done automatically instead of explicitly as I'm doing here. 我相信这是在自动完成验证时完成的,而不是像我在这里那样明确地进行验证。 Changing the javascript described above to look like this: 将上面描述的javascript更改为如下所示:

function DoValidation() {
    if (!Page_ClientValidate('group1')) {
        Page_BlockSubmit = false;
        return false;
    }
    if (!Page_ClientValidate('group2')) {
        Page_BlockSubmit = false;
        return false;
    }

    return true;
}

Causes the problem to go away. 导致问题消失。 Hopefully this will help the next person who makes the same mistake I did. 希望这将有助于下一个犯同样错误的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM