【问题标题】:ASP.net Custom Validator message not displayingASP.net 自定义验证器消息未显示
【发布时间】:2013-04-24 06:15:55
【问题描述】:

我有一个类似于模式弹出窗口的 div。在其中,我需要一个验证,为此我设置了一个自定义验证器。但是消息不会被触发,尽管警报框会触发。

我的代码:

                if ((oldFromTime <= newFromTime) && (oldToTime > newFromTime)) {
                 alert("Choose time ahead of the ones saved earlier.!");
                arguments.IsValid = false;

            }
            else {
                arguments.IsValid = true;

            }

还有我的自定义验证器

<asp:CustomValidator id="cboToTimeMins_CustomValidator" ControlToValidate="cboToTimeMins" ClientValidationFunction="validateTime" Display="static" ErrorMessage="Selected time range falls in the range of the ones saved earlier...! Choose another." runat="server" ValidationGroup="Timetable"/>

cboToTimeMins 是我的下拉框,我需要根据从中选择的值设置验证消息。 我的代码有问题吗?

附:我只需要客户端验证。

【问题讨论】:

  • 你把验证器放在html页面的什么地方?
  • 我先有下拉框..后面是自定义验证器..函数放在文件开头。
  • 当警报事件发生时,您可以尝试使用 firebug 或任何浏览器调试器检查 html 吗?该消息可能由于 css 或布局而被隐藏。
  • 控制台没有显示我正在使用的功能。为什么会这样?
  • 我确定你写的验证函数在那里,因为函数中的alert语句被触发了。我唯一关心的是cboToTimeMins_CustomValidator元素是否未被其他html元素隐藏或阻止。

标签: asp.net validation client


【解决方案1】:

这是我的解决方案。我删除了下拉菜单的自定义验证器并将其添加到按钮中。另外,我删除了 Javascript 函数中的警报消息。

【讨论】:

    【解决方案2】:

    这是我的示例解决方案

                        <td class="normal">Price<span class="required">*</span></td>
                        <td class="normal" colspan="6">
                            <asp:TextBox ID="txtPrice" CssClass="text" Enabled="true" runat="server"  MaxLength="10" Width="100px" />
                             <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPrice"
                                        ErrorMessage="* Please Input Your Price" Display="Dynamic" ValidationGroup="hdrValidation"/>
    
                        </td>
    

    你需要验证

     Page.Validate("hdrValidation")
            If Not Page.IsValid Then Exit Sub
    

    【讨论】:

      猜你喜欢
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      • 2016-07-23
      • 2016-04-20
      • 1970-01-01
      相关资源
      最近更新 更多