asp.netajaxmaskededitextender

Databinding int32 to MaskedEditExtender enabled TextBox


I have a master/detail scheme for editing an asp:GridView using an asp:DetailsView. One of my fields is for a phone number of type int64 (always 10 digits). I would like this field to always be displayed as (###)###-####. My issue is the first digit in the phone number is always truncated for my edit item field which I used a MaskedEditExtender to achieve the formatting.

Here is my EditItemTemplate for the details view:

<cc1:MaskedEditExtender TargetControlID="edtPROJ_Leader_Phone" Mask="(999)999-9999" runat="server" ClearMaskOnLostFocus="false" ClipboardEnabled="true" MaskType="Number" />
<asp:TextBox ID="edtPROJ_Leader_Phone" runat="server" Text='<%# Bind("PROJ_Leader_Phone") %>' ></asp:TextBox>

When my details view is displayed for editing, the text box displays(_23)456-7890 for the integer 1234567890. Also worth noting that if the property MaskType="Number" is removed, the textbox shows: (234)567-890_. I would of course have the textbox show (123)-546-67890 after binding.


Solution

  • Problem could be that you're not using "Escape Characters" for your "(", ")", and "-".

    Might want to change your mask from

    Mask="(999)999-9999"
    

    to

    Mask="\(999\)999\-9999"
    

    According to the documentation, there is no "(", ")", or "-", so you may be telling it to do something unintended. From the section on masks...

    / - Date separator

    : - Time separator

    . - Decimal separator

    , - Thousand separator

    \ - Escape character

    { - Initial delimiter for repetition of masks

    } - Final delimiter for repetition of masks

    Examples

    9999999 - Seven numeric characters

    99/99 - Four numeric characters separated in the middle by a "/"

    http://www.asp.net/ajaxlibrary/act_MaskedEdit.ashx