Sumedh Meshram

A Personal Blog


Ajax .Net 3.5 Control Toolkit MaskedEditExtender Default to PM

MaskedEditExtender can be set to default to PM.

I modified the code from

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" "">
<html xmlns="">
<head runat="server">
    <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() {
            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:
                   mee.setSelectionRange(0, 0);
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <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>

Hope this Help



Comments (1) -

JayPrakash Sharma
India JayPrakash Sharma

Very informative post. Its really helpful for me and beginner too. Check out this link too its also having a nice post with wonderful explanation on ajax toolkit maskededitextendar control in



Add comment

  Country flag

  • Comment
  • Preview