Jquery 验证和更新面板一起使用

发布于 2024-09-19 03:05:12 字数 401 浏览 3 评论 0原文

我正在尝试使用 jqueryvalidation 插件,但我的表单位于更新面板中。因此,即使在提交表单时应用验证后,它也会验证并显示所需的消息几乎 2 秒,然后提交表单。
解决这个问题的方法是什么?

我也尝试过这个。

<asp:UpdatePanel ID="AddUserPanel" runat="server"
             ChildrenAsTriggers="false"
             UpdateMode="Conditional">

但这似乎也没有帮助。

I m trying to use jquery validation plugin but my form is in update panel. So even after applying the validation on submit the form it validates and shows the required message for hardly 2 seconds and then submits the form.
What is the workaround for this?

I have tried this also.

<asp:UpdatePanel ID="AddUserPanel" runat="server"
             ChildrenAsTriggers="false"
             UpdateMode="Conditional">

But this also doesn't seem to help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

几度春秋 2024-09-26 03:05:12

如果您使用脚本管理器,则需要下面的 l33t 代码:

  $(function () {
 //Code that runs before update panel is fired.

        //Listen for update panel
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        //Re-initialize jquery after an auto post back.
        function EndRequestHandler(sender, args) {
            //Do work after update panel fires.
        } 
    });

所以基本上您有重复的代码,即 EndRequestHandler() 外部和内部的代码。

If your using a script manager you need the l33t code below:

  $(function () {
 //Code that runs before update panel is fired.

        //Listen for update panel
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        //Re-initialize jquery after an auto post back.
        function EndRequestHandler(sender, args) {
            //Do work after update panel fires.
        } 
    });

So basically you have duplicate code, code outside of the EndRequestHandler() and inside it.

还给你自由 2024-09-26 03:05:12

您需要返回 false 并停止 onsubmit 上的事件冒泡,如下所示:

$("form").submit(function (e) {
  e.preventDefault();
  return(false);
});

但是我对 ASP 一无所知,所以我不知道这在这种特殊情况下是否有帮助。

也许您需要使用 .live 或在加载此面板中的内容后重新附加处理程序,以便将 onsubmit 事件绑定到它?

You need to return false and stop event bubbling on the onsubmit, something like this:

$("form").submit(function (e) {
  e.preventDefault();
  return(false);
});

However I don't know anything about ASP, so I don't know if that will help in this particular case.

Perhaps you need to use .live or reattach the handler after the content in this panel is loaded in, so the onsubmit events are bound to it?

贪恋 2024-09-26 03:05:12

Asp.net WebForms 使用 __doPostback() 函数来提交表单。

这就是我要做的:

  1. 检查表单提交执行以查看事情是否按预期工作,因此首先进行验证(我很确定它会这样做,因为您确实收到了这些消息)并检查每个单独部分的代码.

  2. 如果验证不能通过调用 preventDefault() 或返回 false 来阻止默认事件执行(冒泡),则应将其更改为足以与Asp.net WebForms。

  3. 如果验证方面一切正常,您应该更改您的 __doPostback() 函数。是的,这听起来确实很黑客,但有时这样的事情必须要做。复制现有代码并添加额外的检查。没什么可担心的。

另请检查这个 Stackoverflow 问题

噢,见鬼。只需对此进行 Google 搜索并仅包含 stackoverflow 结果: jQuery 验证 Web 表单网站:stackoverflow.com

Asp.net WebForms uses the __doPostback() function that submits your form.

This is what I would do:

  1. Check form submit execution to see whether things works as expected so validation happens first (which I'm pretty sure it does because you do get those messages up) and check the code of each individual part.

  2. If validation doesn't prevent default event execution (bubbling) by either returning false of calling preventDefault() or both, then it should be changed to work sufficiently with Asp.net WebForms.

  3. If everything seems to be fine on the validation front, you should change your __doPostback() function. It does sound hackish yes, but sometimes things like this have to be done. Copy existing code and add additional checking. Nothing to worry.

Also check this Stackoverflow question.

Oh hell. Just do a Google search on this and include stackoverflow results only: jQuery validation webforms site:stackoverflow.com

永不分离 2024-09-26 03:05:12

如果我没记错的话,您可以使用常规按钮而不是 asp:button,这不会导致回发。如果是这种情况,那么您可以使用 JavaScript 来更新 UpdatePanel。

If I remember correctly, you can use a regular button instead of the asp:button which will not cause a postback. If this is the case, then you can use JavaScript to update the UpdatePanel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文