When using MaskedEditExtender Masktype time, how to override unwanted behavior?

The following two lines work fine if the 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" /> 

If the user enters "12" and then moves on to the next field, the minutes are filled with the current minute. This is not desirable for this page. I would like to either display an error message or fill in "00" for the missing numbers.

It does not help:

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

since the field is apparently formatted by the time the validator gets its turn on it.

+4
source share
2 answers

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

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

Therefore, your validator should be able to do its job correctly.

+4
source

To fill it: 00, you can set the AutoCompleteValue property to "99:00"

+1
source

Source: https://habr.com/ru/post/1335012/


All Articles