验证后,为什么我的表格寄回? [英] Why won't my form post back after validation?

查看:197
本文介绍了验证后,为什么我的表格寄回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net页面与多个验证摘要设置与 ShowMessageBox =真和几个验证。我所遇到的情况是,当验证正确,但再下点击通常会触发页面回发不会触发回发失败的验证摘要显示。因此,步骤是这样的:

  1. 单击按钮触发验证。
  2. 验证失败,并显示与失败消息的消息框。
  3. 点击不同的按钮,不验证,但应触发回传什么也没发生
  4. 单击相同的按钮,又第3步回发发生如预期。

什么可能导致此行为?

编辑:验证正在以下面的方式完成的。在ASP页面:

 < ASP:按钮=服务器ID =BTN的OnClientClick =返回DoValidation(); />
 

在JavaScript的:

 函数DoValidation(){
    如果(!Page_ClientValidate(组1))
        返回false;
    如果(!Page_ClientValidate('组2'))
        返回false;

    返回true;
}
 

解决方案

这方面的工作,使谨慎使用我终于找到了,当你做验证的方式来描述在编辑一个布尔值设置问题的调试后在失败时,从经历块的页面的下一个回发。我相信这是在验证被自动完成的,而不是明确的,因为我在这里做完成。改变上述的JavaScript来是这样的:

 函数DoValidation(){
    如果(!Page_ClientValidate(组1)){
        Page_BlockSubmit = FALSE;
        返回false;
    }
    如果(!Page_ClientValidate('组2')){
        Page_BlockSubmit = FALSE;
        返回false;
    }

    返回true;
}
 

使问题消失。希望这将有助于在未来的人谁作出了同样的错误,我做到了。

I have an asp.net page with multiple validation summaries setup with ShowMessageBox="True" and several validators. 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.

What could cause this behavior?

EDIT: The validation was being done in the following manner. In the asp page:

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

In the 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. 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:

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.

这篇关于验证后,为什么我的表格寄回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆