How to save values with Mask of RadMaskTextBox into Database

3 posts, 0 answers
  1. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 19 Sep 2012 Link to this post


    Folks,

    Using VS 2010 with RadControls for ASP.NET AJAX Q2 2012 SP1.

    Assuming I  have a SS# with Value 799999991. I would like to display/mask it in Below RadMaskedTextBox as 799-99-9991 also save into database table as 799-99-9991 not as 799999991. Below is declaration.

    Thanks

    gc_0620 


    <telerik:RadMaskedTextBox ID="TxtSoc_Sec_Num"  runat="server" Mask="###-##-####" CssClass="gridTextBox" Text='<%# Bind( "Soc_Sec_Num") %>'>
      
    </telerik:RadMaskedTextBox>
    <asp:RegularExpressionValidator ID="RegularExpressionValidatorTxtSoc_Sec_Num" runat="server"
        Display="None" ErrorMessage="! Soc. Sec# must be in: 999-99-999 Format." ValidationExpression="\d{3}-\d{2}-\d{4}"
        SetFocusOnError="true" ControlToValidate="TxtSoc_Sec_Num">
    </asp:RegularExpressionValidator>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Sep 2012 Link to this post

    Hi,

    You can access the text in the RadMaskedTextBox with the literal characters in the mask using TextWithLiterals property of RadMaskedTextBox as follows.

    ASPX:
    string text = TxtSoc_Sec_Num.TextWithLiterals;

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 20 Sep 2012 Link to this post

    Thanks Shinu,

    Your solution works. I made a small changes in Update event, Because entry of Soc. Sec# is optional. But if user enters it, must be 9 digits. 

    Below is the changes

    if (txtssnum.Text.ToString() != string.Empty && txtssnum.Text.Trim().Length < 9)
    {
    message = "If entered, Soc. Sec# must be in: 999-99-999 Format!";
    cleanMessage = message.Replace("'", "\'");
    RadAjaxPanel1.ResponseScripts.Add(string.Format("alert('" + cleanMessage + "');"));
    e.Canceled = true;
    return;
    }
    else
    {
    string stssnum = txtssnum.TextWithLiterals;
    }

    Gc_0620

Back to Top