locked
MaskedEditExtender SSN RRS feed

  • Question

  • User1652530521 posted

    Hi,

    How can I use MaskedEditExtender  on a textbox for social security number?

    Thanks

    Sunday, September 20, 2015 5:03 AM

Answers

  • User-183374066 posted

    Register toolkit 

    <%@ Register TagPrefix="AjaxControlToolkit" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit, Version=15.1.3.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>

    and your Extender

    <asp:TextBox runat="server" ID="txtSSN"></asp:TextBox>
    <AjaxControlToolkit:MaskedEditExtender runat="server" ID="eSsn" TargetControlID="txtSSN" Mask="999-99-9999" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError" MaskType="Number" ErrorTooltipEnabled="True" ClearMaskOnLostFocus="False" />
    <asp:Button runat="server" ID="btn" Text="Save" OnClick="btn_Click" />

    and code behind

    protected void btn_Click(object sender, EventArgs e)
    {
        var plainSSN = txtSSN.Text.Replace("-", "");
    }

    Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 20, 2015 6:18 AM

All replies

  • User-183374066 posted

    Register toolkit 

    <%@ Register TagPrefix="AjaxControlToolkit" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit, Version=15.1.3.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>

    and your Extender

    <asp:TextBox runat="server" ID="txtSSN"></asp:TextBox>
    <AjaxControlToolkit:MaskedEditExtender runat="server" ID="eSsn" TargetControlID="txtSSN" Mask="999-99-9999" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError" MaskType="Number" ErrorTooltipEnabled="True" ClearMaskOnLostFocus="False" />
    <asp:Button runat="server" ID="btn" Text="Save" OnClick="btn_Click" />

    and code behind

    protected void btn_Click(object sender, EventArgs e)
    {
        var plainSSN = txtSSN.Text.Replace("-", "");
    }

    Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 20, 2015 6:18 AM
  • User1652530521 posted

    Thanks for the answer. I noticed today that if no SSN was entered then something like this _________-____-_______  is saved in the db. If user doesn't enter a SSN I want null or empty to be saved.

    Is this a known behaviour or is it a bug that I have?

    Thanks

    Monday, September 21, 2015 3:11 PM
  • User2103319870 posted

    I noticed today that if no SSN was entered then something like this _________-____-_______  is saved in the db. If user doesn't enter a SSN I want null or empty to be saved.

    Is this a known behaviour or is it a bug that I have?

    You have set the 'ClearMaskOnLostFocus' property of MaskEditExtender to false. Set that to True and and you will get empty values on serverside if user didnt provide a number

    <asp:TextBox ID="txtSSN" runat="server"></asp:TextBox>
            <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="txtSSN" Mask="999-99-9999" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError" MaskType="Number" ErrorTooltipEnabled="True" ClearMaskOnLostFocus="true" >
            </ajaxToolkit:MaskedEditExtender>

    Tuesday, September 22, 2015 1:55 PM