0

我有 2 个接受用户时间的文本框,我将 Maskededitextender 和 maskededitvalidator 设置为如下:

文本框 1:

<asp:TextBox ID="txtInTime" Text ="00:00" CssClass="txtbox" MaxLength="5" 
                                        Width="43px" runat="server" ValidationGroup="date" 
                                       ></asp:TextBox>



                     <cc1:MaskedEditExtender ID="MaskedEditExtender2" runat="server"  TargetControlID="txtInTime"
                        Mask="99:99" MessageValidatorTip="true" MaskType="Time" InputDirection="RightToLeft"
                        ErrorTooltipEnabled="True" />                      

                    <cc1:MaskedEditValidator ID="MaskedEditValidator2"  runat="server" ControlExtender="MaskedEditExtender2"
                        ControlToValidate="txtInTime"  MaximumValue="23:59" MinimumValue="00:00"
                       MaximumValueMessage="23:59"  ValidationGroup="date"
                        InvalidValueBlurredMessage="Time Invalid"
                        MinimumValueMessage="Time must be greater than 00:00:00"  ForeColor ="Red" 
                        ToolTip="Enter time between 00:00 to 23:59">
                        </cc1:MaskedEditValidator>

文本框 2:

 <asp:TextBox ID="txtOutTime" Text ="00:00" CssClass="txtbox" MaxLength="5" 
                                        Width="43px" runat="server" ValidationGroup="date" 
                                       ></asp:TextBox>



                     <cc1:MaskedEditExtender ID="MaskedEditExtender3" runat="server"  TargetControlID="txtOutTime"
                        Mask="99:99" MessageValidatorTip="true" MaskType="Time" InputDirection="RightToLeft"
                        ErrorTooltipEnabled="True" />                      

                    <cc1:MaskedEditValidator ID="MaskedEditValidator1"  runat="server" ControlExtender="MaskedEditExtender3"
                        ControlToValidate="txtOutTime"  MaximumValue="23:59" MinimumValue="00:00"
                       MaximumValueMessage="23:59" ValidationGroup="date"
                        InvalidValueBlurredMessage="Time Invalid"
                        MinimumValueMessage="Time must be grater than 00:00:00"  ForeColor ="Red" 
                        ToolTip="Enter time between 00:00 to 23:59">
                        </cc1:MaskedEditValidator>

然后我有一个按钮,其点击过程发生,但如果 maskededitvalidator 显示无效数据,则按钮后面的代码不得执行。但在我的情况下,尽管 maskededitvalidator 显示无效数据,但后面的代码仍会执行。我已经设置了所有相关控件的验证组,但是问题。

按钮:

<asp:Button ID="btnLoadEmployees"  ValidationGroup="date" CssClass="button" runat="server" Text="Load Employees" OnClick="btnLoadEmployees_Click"/>

请大家帮帮我。

4

1 回答 1

0

尝试这个:

    Please Enter Time:
    <asp:TextBox ID="txtBoxTime" runat="server"></asp:TextBox>
    <ajax:MaskedEditExtender ID="MaskedEditExtender3" runat="server" TargetControlID="txtBoxTime"
    Mask="99:99:99" MaskType="Time" MessageValidatorTip="true" InputDirection="RightToLeft" >
    </ajax:MaskedEditExtender>
    <ajax:MaskedEditValidator ID="MaskedEditValidator3" runat="server" ControlExtender="MaskedEditExtender3"
     ControlToValidate="txtBoxTime" IsValidEmpty="false" MaximumValue="23:59:59" MinimumValue="00:00:00"
     EmptyValueMessage="Please enter time"
     MaximumValueMessage="Please enter time less than 23:59:59" MinimumValueMessage="Please enter time greater than 00:00:00" >
    </ajax:MaskedEditValidator>

参考:http: //www.devasp.net/net/articles/display/1373.html

不要忘记放置验证组

于 2014-09-18T05:04:44.197 回答