Sumedh Meshram

.Net Technical Blog

Ajax .Net 3.5 Control Toolkit MaskedEditExtender Default to PM

MaskedEditExtender can be set to default to PM.

I modified the code from http://forums.asp.net/t/1339632.aspx

to this

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SoluTest_Mask._Default" %>
 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 
    <script type="text/javascript">
        //Set the default text to "PM"
        var mee;
        function pageLoad() {
            //Please use your MaskedEditExtender's id or behaviorId.
            mee = $find("MaskedEditExtender3");
 
            //The target textbox control
            var e = mee.get_element();
 
            //Remove the focus event handler
            if (mee._focusHandler) {
                $removeHandler(e, "focus", mee._focusHandler);
            }
            //Add a new focus event handler which inherits from the old one.
            mee._focusHandler = Function.createDelegate(mee, newFocus);
            $addHandler(e, "focus", mee._focusHandler);
        }
        function newFocus() {
            mee._onFocus();
            if ((mee._MaskType == AjaxControlToolkit.MaskedEditType.Time || mee._MaskType == AjaxControlToolkit.MaskedEditType.DateTime) && mee.get_CultureAMPMPlaceholder() != "" && mee._getClearMask() == "") {
                if (mee._AcceptAmPm) {
                    //The original code of default AM/PM text in function _onFocus() is:
                    //this.InsertAMPM(this.get_CultureAMPMPlaceholder().substring(0,1));
 
                   mee.InsertAMPM(meeTueEndCorp.get_CultureFirstLetterPM());
                   mee.setSelectionRange(0, 0);
                }
            }
        }
    </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <strong>Enter Time (format: <em>99:99:99</em>):</strong>
        <br />
        <asp:TextBox ID="TextBox3" runat="server" Width="130px" Height="16px" />
        <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender3" runat="server" TargetControlID="TextBox3"
            Mask="99:99:99" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus"
            OnInvalidCssClass="MaskedEditError" MaskType="Time" AcceptAMPM="True" ErrorTooltipEnabled="True" />
        <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator3" runat="server" ControlExtender="MaskedEditExtender3"
            ControlToValidate="TextBox3" IsValidEmpty="False" EmptyValueMessage="Time is required"
            InvalidValueMessage="Time is invalid" Display="Dynamic" TooltipMessage="Input a time"
            EmptyValueBlurredText="*" InvalidValueBlurredMessage="*" />
        <br />
        <em><span style="font-size: 8pt">Tip: Type 'A' or 'P' to switch AM/PM</span></em>
    </div>
    </form>
</body>
</html>

Hope this Help

Sumedh

 

Cheap MLB Jerseys maillot de foot pas cher www.fotballdrakter.org