当使用Masktype时间MaskedEditExtender,如何覆盖的不良行为?不良行为、时间、Masktype、MaskedEditExtender

2023-09-10 16:54:06 作者:我要的幸福就是你幸福

下面两行正常工作时,可以正确指定的输入:

The following two lines work fine when input is correctly specified:

<asp:TextBox ID="MondayOpenTextBox" runat="server" MaxLength="5" />
<Ajax:MaskedEditExtender ID="MondayOpenMaskedEditExtender" runat="server" 
    TargetControlID="MondayOpenTextBox" AcceptAMPM="false" MaskType="Time" 
    Mask="99:99" />

如果用户输入12,然后按Tab切换到下一个领域,分钟,并填充当前分钟。这是不希望的对所讨论的页。我想无论是喜欢弹出一个错误信息,或填写00为跳过的数字。

If the user enters "12" then tabs to the next field, the minutes get populated with the current minute. This is not desirable for the page in question. I'd either like to popup an error message, or fill in "00" for the skipped digits.

这没有帮助:

<asp:RegularExpressionValidator runat="server" ID="ValidateMondayOpenTextBox" 
    ControlToValidate="MondayOpenTextBox" Display="Dynamic" ErrorMessage="X" 
    ValidationExpression="\d\d:\d\d" />

作为字段由时间显然格式化确认器得到轮到它在它

as the field is apparently formatted by the time the validator gets its turn at it.

推荐答案

您可以设置您的 MaskedEdit 扩展到以prevent它填满空屏蔽字符与当前时间:

You can set the AutoComplete property of your MaskedEdit extender to false in order to prevent it from filling the empty masked characters with the current time:

<Ajax:MaskedEditExtender ID="MondayOpenMaskedEditExtender" runat="server"
    TargetControlID="MondayOpenTextBox" AcceptAMPM="false" MaskType="Time"
    Mask="99:99" AutoComplete="False" />

这样,您的验证程序应能正确地完成其工作。

That way, your validator should be able to properly do its job.