【问题标题】:Why won't my RequiredValidator work inside this Jquery dialog box?为什么我的RequiredValidator 不能在这个Jquery 对话框中工作?
【发布时间】:2011-04-14 00:00:12
【问题描述】:

我有一个对话框,允许用户在提交到服务器之前输入一些文本。文字为必填项。

我的代码是这样的

这是打开对话框的 Jquery 代码

     function onReportThis() {
     $("#dialog-Report").dialog({
         resizable: false,
         modal: true,
         width: '400px',
         buttons: {
             Submit: function () {

                 __doPostBack('<%= lnkReportThis.UniqueID %>', '');

                 //                     onReported();
             },
             Cancel: function () {
                 $(this).dialog("close");
             }
         }
     });
     $("#dialog-Report").parent().appendTo(jQuery("form:first"));
    return false;
}

这是盒子本身的代码。

    <div id="dialog-Report" style="display: none" title="Report This Profile">
    <p>
        I am reporting this profile because</p>
    <asp:RequiredFieldValidator ID="validReportText" ControlToValidate="txtReportDetail" runat="server" ErrorMessage="Please enter text" ></asp:RequiredFieldValidator>
    <p>
        Please enter additional details regarding why you are reporting this profile</p>
    <asp:TextBox ID="txtReportDetail" runat="server" Width="300px" Height="300px" TextMode="MultiLine" />
</div>

在回调之前未使用必填字段验证器。我怎样才能让它工作?谢谢

更新:我已经开始工作了。

我必须这样做。

                     if (Page_ClientValidate()) {
                     __doPostBack('<%= lnkReportThis.UniqueID %>', '');
                 }

【问题讨论】:

    标签: jquery asp.net validation jquery-ui


    【解决方案1】:

    我的朋友,你正处于一个受伤的世界……但要回答你的问题,你需要在调用 __dosubmit() 方法之前手动触发验证事件。

    这篇文章解释了如何做这个客户端:http://fczaja.blogspot.com/2009/07/aspnet-how-to-trigger-client-side.html

    基本上,您想在提交之前致电Page_ClientValidate();

    【讨论】:

    • 事实证明你是对的。我没有意识到 DoPostback 没有自动验证它。我使用了 Page_ClientValidate() 方法并且它有效。谢谢!
    猜你喜欢
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多