This is a migrated thread and some comments may be shown as answers.

How to save values with Mask of RadMaskTextBox into Database

2 Answers 297 Views
Input
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 19 Sep 2012, 08:38 PM

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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Sep 2012, 07:29 AM
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.
0
gc_0620
Top achievements
Rank 1
answered on 20 Sep 2012, 09:07 PM

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

Tags
Input
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
gc_0620
Top achievements
Rank 1
Share this question
or