ASP.net自定义验证器消息不显示

时间:2013-04-24 06:15:56

标签: asp.net validation client

我有一个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是我的下拉框,我需要根据从中选择的值设置验证消息。 我的代码中有什么问题吗?

P.S。我只需要CLIENT SIDE验证。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

这是我的示例解决方案

                    <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