JQuery 与 Asp.net 验证

发布于 2024-09-07 08:24:58 字数 1231 浏览 3 评论 0 原文

我有一个表单,显示一个 asp.net 网格,网格中列出了不同的人。 用户可以通过单击页面上的 asp.net 按钮将新用户添加到网格中:

单击此按钮时,将打开一个 JQuery 对话框:

        $(document).ready(function() {
    $('#content_button #ctl00_MainContent_btnAddPerson').each(function() {
            var $link = $(this);
            var $dialog = $('<div></div>')
        .load($link.attr('title') + ' #content_dialogBox')
        .dialog({
            autoOpen: false,
            title: $link.attr('value'),
            width: 500,
            beforeclose: function() { window.location = "ManagePeople.aspx" }
        });
            $link.click(function() {
                $dialog.dialog('open');

                return false;
            });
        });
    });

这一切都工作正常。但是,对话框表单上的某些字段必须进行验证。起初,我使用了asp.net必填字段验证。由于某种原因,这不起作用。所以,我在代码隐藏中进行验证。验证有效(就像对所需字段控件所做的那样),但表单显示在它自己的窗口中,而不是在 JQuery 对话框中。有人可以告诉我我做错了什么吗?

注意:ManagePeople.aspx 是包含网格的页面。单击 addperson 按钮后,将显示 AddPerson.aspx 中 #content_dialogBox 的内容。

I have a form that displays an asp.net grid with different people listed in the grid.
A user can add new user's to the grid, by clicking an asp.net button on the page:

<div id="content_button">
    <asp:Button ID="btnAddperson" runat="server"
CssClass="content_button"
        PostBackUrl="addperson.aspx" Text="Add
Person" 
        ToolTip="addPerson.aspx" />
</div>

When this button is clicked, a JQuery dialog is opens:

        $(document).ready(function() {
    $('#content_button #ctl00_MainContent_btnAddPerson').each(function() {
            var $link = $(this);
            var $dialog = $('<div></div>')
        .load($link.attr('title') + ' #content_dialogBox')
        .dialog({
            autoOpen: false,
            title: $link.attr('value'),
            width: 500,
            beforeclose: function() { window.location = "ManagePeople.aspx" }
        });
            $link.click(function() {
                $dialog.dialog('open');

                return false;
            });
        });
    });

This all works fine. However, there are some fields on the dialog form that have to be validated. At first, I used asp.net required field validation. For some reason, that didn't work. So, I am validating in the code-behind. The validation works (as it did with the required field controls), but the form displays in it's own window, instead of within the JQuery dialog. Can someone please tell me what I'm doing wrong.

Note: ManagePeople.aspx is the page that contains the grid. Once the addperson button is clicked the contents of the #content_dialogBox in the AddPerson.aspx is displayed.

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

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

发布评论

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

评论(1

∝单色的世界 2024-09-14 08:24:58

您是否尝试过使用 JQuery Validation 插件进行客户端验证?另外,您使用什么进行服务器端验证。我希望它是 FluentValidation。它让您的生活变得非常轻松。

http://docs.jquery.com/Plugins/Validation

Have you tried using the JQuery Validation plugin for client side validation? Also, what are you using for Server Side validation. I hope it is FluentValidation. It makes life very easy for you.

http://docs.jquery.com/Plugins/Validation

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