ajaxToolkit:MaskedEditExtender - is there a way to write a custom MaskType or can I use "Time" after all?

4k Views Asked by At

I'm trying to use ajaxToolkit:MaskedEditExtender for a time interval input. Now I want to be able to allow for hours:minutes, but the way I do it, it only allows for 00:00 to 23:59. I however need it to also allow 999:59, i.e. I don't want a time of the day but to set an interval.

               <ajaxToolkit:MaskedEditExtender 
                    runat="server" 
                    ID="StartTimeMaskedEdit" 
                    MaskType="Time" 
                    Mask="999:99" 
                    TargetControlID="TimeOutTextBox" 
                    ClearMaskOnLostFocus="true" 
                    AutoComplete="true" 
                    AutoCompleteValue="000:00" />          

               <ajaxToolkit:MaskedEditValidator 
                    runat="server" ID="StartTimeMaskedEditValidator" 
                    ControlExtender="StartTimeMaskedEdit" 
                    ControlToValidate="TimeOutTextBox" 
                    IsValidEmpty="false" 
                    InvalidValueMessage="*Invalid Time" 
                    InvalidValueBlurredMessage="*Invalid Time" />

When I use MaskType="number", the problem is such that the colon disappears once the input field loses focus (probably because a colon is not a valid part of a number). It reappears on focus, but that's not good enough.

Is there a way to write a custom MaskType or to allow for the above within the MaskType="Time" or "number" constaints ?

3

There are 3 best solutions below

0
On BEST ANSWER

I removed the validation part and do so in the codebehind now

0
On
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender2" runat="server"
                        TargetControlID="txtRestaurantMacID"
                        Mask="NL {2}:NL {2}:NL {2}:NL {2}:NL {2}:NL {2}"
                        ClearMaskOnLostFocus="true"
                        ClearTextOnInvalid="true"
                        MessageValidatorTip="true"
                        OnFocusCssClass="MaskedEditFocus"
                        OnInvalidCssClass="MaskedEditError"
                        MaskType="None"
                        InputDirection="LeftToRight"
                        ErrorTooltipEnabled="True" />

and Use also validator

 <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator2" runat="server"
                    ControlExtender="MaskedEditExtender2"
                    ControlToValidate="txtRestaurantMacID"
                    ValidationExpression="^([0-9a-fA-F]{2}){5}[0-9a-fA-F]{2}$"
                    IsValidEmpty="False"
                    Display="Dynamic"
                    TooltipMessage="Enter valid Mac Id"
                    EmptyValueBlurredText="*"
                    InvalidValueBlurredMessage="*"
                    MaximumValueBlurredMessage="*"
                    MinimumValueBlurredText="*"
                    ForeColor="Red"
                    ValidationGroup="addres" />
1
On

Try as below code :

<ajaxToolkit:MaskedEditExtender ID="StartTimeMaskedEdit" runat="server" 
                        TargetControlID="TimeOutTextBox" Mask="999:99:99" 
                        MessageValidatorTip="true" MaskType="Time" CultureName="en-us" 
                        InputDirection="RightToLeft" ErrorTooltipEnabled="True" />


<ajaxToolkit:MaskedEditValidator ID="StartTimeMaskedEditValidator" runat="server" 
                         ControlExtender="StartTimeMaskedEdit"
                         ControlToValidate="TimeOutTextBox" IsValidEmpty="false" 
                         MaximumValue="23:59:59" MinimumValue="00:00:00"
                         EmptyValueMessage="Enter Time" 
                         MaximumValueMessage="23:59:59" 
                         InvalidValueBlurredMessage="Time is Invalid"
                         MinimumValueMessage="Time must be grater than 00:00:00"
                         EmptyValueBlurredText="*"
                         ToolTip="Enter time between 00:00:00 to 23:59:59">   
</asp:MaskedEditValidator>

I hope it's work and help you