New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial

RadMaskedTextBox is an enhanced data entry control that uses a mask to distinguish between proper and improper user input. It shares the common properties of all RadInput controls, including support for skins, styles for different states, empty message support, conditional postback on text change, flexible caret and button positioning, labels, and so on.

Definition

Namespace:Telerik.Web.UI

Assembly:Telerik.Web.UI.dll

Syntax:

C#
[ClientScriptResource("Telerik.Web.UI.RadMaskedTextBox", "Telerik.Web.UI.Input.MaskedTextBox.RadMaskedInputScript.js")]
[RequiredScript(typeof(RadTextBox))]
[ToolboxBitmap(typeof(RadMaskedTextBox), "Toolbox.Icons.MaskedTextbox.png")]
[ValidationProperty("ValidationText")]
[ControlValueProperty("Text")]
[TelerikToolboxCategory("Data Editing")]
public class RadMaskedTextBox : RadInputControl, IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor, IAttributeAccessor, IScriptControl, IControlResolver, IPostBackDataHandler, ISkinnableControl, IControl, IPostBackEventHandler, INamingContainer, IEditableTextControl, ITextControl

Inheritance: objectControlWebControlRadWebControlRadInputControlRadMaskedTextBox...

Implements: IAttributeAccessorIComponentIControlIControlBuilderAccessorIControlDesignerAccessorIControlResolverIDataBindingsAccessorIDisposableIEditableTextControlIExpressionsAccessorINamingContainerIParserAccessorIPostBackDataHandlerIPostBackEventHandlerIScriptControlISkinnableControlITextControlIUrlResolutionService...

Inherited Members RadInputControl.setWidthRadInputControl.setHeightRadInputControl.setStyleRadInputControl.OnChildrenCreated()RadInputControl.isOnlyInputRendered()RadInputControl.shouldRenderWhiteSpace()RadInputControl.ApplyCurrentCssClass(HtmlTextWriter)RadInputControl.Focus()RadInputControl.SetStyleClasses()RadInputControl.StylesToClient()RadInputControl.FormatCssClass(string, string)RadInputControl.ControlPreRender()RadInputControl.MergeStyles()RadInputControl.MergeAuxiliaryStyles()RadInputControl.OnTextChanged(EventArgs)RadInputControl.CalculateWrapperWidth()RadInputControl.CalculateInputWidth()RadInputControl.RenderBeginTagSingleInput(HtmlTextWriter)RadInputControl.RenderBrowserSpecificStyles(HtmlTextWriter)RadInputControl.RenderInnerWrapperContent(HtmlTextWriter)RadInputControl.RenderContentsSingleInput(HtmlTextWriter)RadInputControl.RenderContents(HtmlTextWriter)RadInputControl.RenderPasswordStrengthIndicator(HtmlTextWriter, bool)RadInputControl.GetOffsetAdditionalClasses()RadInputControl.RenderChildren(HtmlTextWriter)RadInputControl.RenderLabel(HtmlTextWriter, string)RadInputControl.DescribeValueAndTextProperties(IScriptDescriptor)RadInputControl.GetPostBackEventReference()RadInputControl.SetDesignTimeAttributes(HtmlTextWriter)RadInputControl.CreateChildControls()RadInputControl.LoadPostData(string, NameValueCollection)RadInputControl.RaisePostDataChangedEvent()RadInputControl.RegisterScriptControl()RadInputControl.EnableSingleInputRenderingRadInputControl.LabelRadInputControl.TagNameRadInputControl.LabelCssClassRadInputControl.AutoPostBackRadInputControl.AutoCompleteTypeRadInputControl.TextElementIDRadInputControl.CausesValidationRadInputControl.EmptyMessageRadInputControl.InvalidStyleDurationRadInputControl.BrowserRadInputControl.ClientEventsRadInputControl.ShowButtonRadInputControl.ButtonsPositionRadInputControl.ButtonCssClassRadInputControl.WrapperCssClassRadInputControl.ValidationTextRadInputControl.DisplayTextRadInputControl.ValidationGroupRadInputControl.DisplayRadInputControl.EnableAriaSupportRadInputControl.EmptyMessageStyleRadInputControl.ReadOnlyStyleRadInputControl.FocusedStyleRadInputControl.DisabledStyleRadInputControl.InvalidStyleRadInputControl.InvalidRadInputControl.HoveredStyleRadInputControl.EnabledStyleRadInputControl.WidthRadInputControl.LabelWidthRadInputControl.EnableOldBoxModelRadInputControl.ShouldResetWidthInPixelsRadInputControl.HeightRadInputControl.AccessKeyRadInputControl.BackColorRadInputControl.BorderColorRadInputControl.BorderStyleRadInputControl.BorderWidthRadInputControl.CssClassRadInputControl.EnableAjaxSkinRenderingRadInputControl.EnabledRadInputControl.EnableEmbeddedBaseStylesheetRadInputControl.EnableEmbeddedScriptsRadInputControl.EnableEmbeddedSkinsRadInputControl.VisibleRadInputControl.ToolTipRadInputControl.EnableThemingRadInputControl.EnableViewStateRadInputControl.TabIndexRadInputControl.SkinIDRadInputControl.SupportsRenderingModeRadInputControl.EmptySkinRadInputControl.ResizableRadInputControl.defaultWidthRadInputControl.ButtonContainerRadInputControl.ButtonsLightContainerRadInputControl.LastSetTextBoxValueRadInputControl.ChildrenCreatedRadInputControl.TextChangedWebControl.ApplyStyle(Style)WebControl.CopyBaseAttributes(WebControl)WebControl.CreateControlStyle()WebControl.MergeStyle(Style)WebControl.Render(HtmlTextWriter)WebControl.RenderBeginTag(HtmlTextWriter)WebControl.RenderEndTag(HtmlTextWriter)WebControl.AttributesWebControl.ControlStyleWebControl.ControlStyleCreatedWebControl.DisabledCssClassWebControl.StyleWebControl.FontWebControl.ForeColorWebControl.HasAttributesWebControl.IsEnabledWebControl.SupportsDisabledAttributeControl.ResolveAdapter()Control.HasEvents()Control.GetRouteUrl(object)Control.GetRouteUrl(string, object)Control.GetRouteUrl(RouteValueDictionary)Control.GetRouteUrl(string, RouteValueDictionary)Control.GetUniqueIDRelativeTo(Control)Control.ApplyStyleSheetSkin(Page)Control.OnDataBinding(EventArgs)Control.DataBind()Control.DataBind(bool)Control.DataBindChildren()Control.EnsureID()Control.OnInit(EventArgs)Control.ClearChildState()Control.ClearChildControlState()Control.ClearChildViewState()Control.ClearEffectiveClientIDMode()Control.ClearCachedClientID()Control.LoadControlState(object)Control.MapPathSecure(string)Control.OpenFile(string)Control.OnLoad(EventArgs)Control.BuildProfileTree(string, bool)Control.SaveControlState()Control.RenderControl(HtmlTextWriter)Control.RenderControl(HtmlTextWriter, ControlAdapter)Control.OnUnload(EventArgs)Control.Dispose()Control.RaiseBubbleEvent(object, EventArgs)Control.OnBubbleEvent(object, EventArgs)Control.AddedControl(Control, int)Control.CreateControlCollection()Control.ResolveUrl(string)Control.ResolveClientUrl(string)Control.FindControl(string)Control.FindControl(string, int)Control.GetDesignModeState()Control.HasControls()Control.IsLiteralContent()Control.EnsureChildControls()Control.RemovedControl(Control)Control.SetDesignModeState(IDictionary)Control.SetRenderMethodDelegate(RenderMethod)Control.ClientIDModeControl.ClientIDControl.ClientIDSeparatorControl.ContextControl.AdapterControl.DesignModeControl.EventsControl.IDControl.IsChildControlStateClearedControl.ViewStateModeControl.IsViewStateEnabledControl.NamingContainerControl.IdSeparatorControl.LoadViewStateByIDControl.PageControl.RenderingCompatibilityControl.TemplateControlControl.ParentControl.TemplateSourceDirectoryControl.AppRelativeTemplateSourceDirectoryControl.SiteControl.UniqueIDControl.HasChildViewStateControl.ControlsControl.ValidateRequestModeControl.ViewStateControl.ViewStateIgnoresCaseControl.ChildControlsCreatedControl.IsTrackingViewStateControl.DisposedControl.DataBindingControl.InitControl.LoadControl.PreRenderControl.Unloadobject.ToString()object.Equals(object)object.Equals(object, object)object.ReferenceEquals(object, object)object.GetHashCode()object.GetType()object.MemberwiseClone()...

Constructors

C#
public RadMaskedTextBox()

Properties

Gets or sets a value which determines if empty mask parts are allowed.

C#
[ClientControlProperty]
public bool AllowEmptyEnumerations { get; set; }
Property Value:

A value which determines if empty mask parts are allowed.

Gets or sets the number columns.

C#
public virtual int Columns { get; set; }
Property Value:

The number columns.

Gets or sets the format position when the RadMaskedTextBox is in display mode.

C#
[ClientControlProperty]
public DisplayFormatPosition DisplayFormatPosition { get; set; }
Property Value:

The format position when the RadMaskedTextBox is in display mode.

Gets or sets the display mask which is shown when the RadMaskedTextBox is not focused.

C#
public string DisplayMask { get; set; }
Property Value:

The display mask which is shown when the RadMaskedTextBox is not focused.

Gets the MaskPartCollection which determines which mask parts will be used when the RadMaskedTextBox is not focused.

C#
public MaskPartCollection DisplayMaskParts { get; }
Property Value:

The display mask parts.

Gets or sets the prompt character used in the display mask.

C#
[ClientControlProperty]
public virtual string DisplayPromptChar { get; set; }
Property Value:

The prompt character used in the display mask.

Gets or sets if the prompt will be hidden when RadMaskedTextBox is blurred.

C#
[ClientControlProperty]
public bool HideOnBlur { get; set; }
Property Value:

The hide on blur.

C#
protected virtual MaskPartCollection InitialDisplayMasks { get; }
C#
protected virtual string InitialHiddenFieldValue { get; }
C#
protected virtual MaskPartCollection InitialMasks { get; }

Gets or sets the RadMaskedTextBox mask.

C#
public string Mask { get; set; }
Property Value:

The RadMaskedTextBox mask.

Gets the mask parts of a RadMaskedTextBox which determine which masks will be used for the control.

C#
public MaskPartCollection MaskParts { get; }
Property Value:

The mask parts of a RadMaskedTextBox which determine which masks will be used for the control.

Gets or sets the maximum number of characters allowed in the text box.

C#
[Browsable(false)]
public override int MaxLength { get; set; }
Property Value:

The maximum number of characters allowed in the text box. The default is 0, which indicates that the property is not set.

Overrides: RadInputControl.MaxLength

Use the MaxLength property to limit the number of characters that can be entered in the RadInput control. This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and Introduction to ASP.NET Themes.

Example:
cs-api-definition
</%@ Page Language="C#" AutoEventWireup="True" /%>

</%@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="radI" /%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<title>RadTextBox Example </title>


<script runat="server">


protected void AddButton_Click(Object sender, EventArgs e)
{

int Answer;


Answer = Convert.ToInt32(Value1.Text) + Convert.ToInt32(Value2.Text);


AnswerMessage.Text = Answer.ToString();


}


</script>


</head>
<body>
<form id="form1" runat="server">

<h3>
RadTextBox Example
</h3>
<table>

<tr>
<td colspan="5">
Enter integer values into the text boxes.

<br />
Click the Add button to add the two values.

<br />
Click the Reset button to reset the text boxes.

</td>
</tr>
<tr>
<td colspan="5">


</td>
</tr>
<tr align="center">

<td>

<radI:RadTextBox ID="Value1" Columns="2" MaxLength="3" Text="1" runat="server" />

</td>
<td>
+
</td>

<td>
<radI:RadTextBox ID="Value2" Columns="2" MaxLength="3" Text="1" runat="server" />

</td>
<td>
=
</td>

<td>
<asp:Label ID="AnswerMessage" runat="server" />
</td>

</tr>
<tr>
<td colspan="2">

<asp:RequiredFieldValidator ID="Value1RequiredValidator" ControlToValidate="Value1"

ErrorMessage="Please enter a value.<br />" Display="Dynamic" runat="server" />

<asp:RangeValidator ID="Value1RangeValidator" ControlToValidate="Value1" Type="Integer"

MinimumValue="1" MaximumValue="100" ErrorMessage="Please enter an integer <br /> between than 1 and 100.<br />"

Display="Dynamic" runat="server" />
</td>
<td colspan="2">

<asp:RequiredFieldValidator ID="Value2RequiredValidator" ControlToValidate="Value2"

ErrorMessage="Please enter a value.<br />" Display="Dynamic" runat="server" />

<asp:RangeValidator ID="Value2RangeValidator" ControlToValidate="Value2" Type="Integer"

MinimumValue="1" MaximumValue="100" ErrorMessage="Please enter an integer <br /> between than 1 and 100.<br />"

Display="Dynamic" runat="server" />
</td>
<td>

&nbsp
</td>
</tr>
<tr align="center">

<td colspan="4">
<asp:Button ID="AddButton" Text="Add" OnClick="AddButton_Click" runat="server" />

</td>
<td>


</td>
</tr>
</table>
</form>
</body>
</html>

Gets or sets alignment of numeric ranges.

C#
public NumericRangeAlign NumericRangeAlign { get; set; }
Property Value:

The alignment of numeric ranges.

Gets or sets the prompt char.

C#
[ClientControlProperty]
public virtual string PromptChar { get; set; }
Property Value:

The prompt char.

Gets or sets a value indicating whether the contents of the RadInput control can be changed.

C#
[ClientControlProperty]
public override bool ReadOnly { get; set; }
Property Value:

true if the contents of the RadInput control cannot be changed; otherwise, false. The default value is false.

Overrides: RadInputControl.ReadOnly

Use the ReadOnly property to specify whether the contents of the RadInput control can be changed. Setting this property to true will prevent users from entering a value or changing the existing value. Note that the user of the RadInput control cannot change this property; only the developer can. The Text value of a RadInput control with the ReadOnly property set to true is sent to the server when a postback occurs, but the server does no processing for a read-only RadInput. This prevents a malicious user from changing a Text value that is read-only. The value of the Text property is preserved in the view state between postbacks unless modified by server-side code. This property cannot be set by themes or style sheet themes.

Example:
cs-api-definition
</%@ Page Language="C#" AutoEventWireup="True" /%>

</%@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="radI" /%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<title>MultiLine TextBox Example </title>


<script runat="server">
protected void SubmitButton_Click(Object sender, EventArgs e)

{


Message.Text = "Thank you for your comment: <br />" + Comment.Text;


}


protected void Check_Change(Object sender, EventArgs e)
{


Comment.Wrap = WrapCheckBox.Checked;
Comment.ReadOnly = ReadOnlyCheckBox.Checked;


}


</script>


</head>
<body>
<form id="form1" runat="server">
<h3>

MultiLine TextBox Example
</h3>
Please enter a comment and click the submit button.

<br />
<br />

<radI:RadTextBox ID="Comment" TextMode="MultiLine" Columns="50" Rows="5" runat="server" />

<br />
<asp:RequiredFieldValidator ID="Value1RequiredValidator" ControlToValidate="Comment"

ErrorMessage="Please enter a comment.<br />" Display="Dynamic" runat="server" />

<asp:CheckBox ID="WrapCheckBox" Text="Wrap Text" Checked="True" AutoPostBack="True"

OnCheckedChanged="Check_Change" runat="server" />


<asp:CheckBox ID="ReadOnlyCheckBox" Text="ReadOnly" Checked="False" AutoPostBack="True"

OnCheckedChanged="Check_Change" runat="server" />


<asp:Button ID="SubmitButton" Text="Submit" OnClick="SubmitButton_Click" runat="server" />

<hr />
<asp:Label ID="Message" runat="server" />
</form>
</body>

</html>

Gets or sets if it is required to complete entered text in the RadMaskedTextBox. By default is 'false'. Set to 'true' if you want full text to be required.

C#
public bool RequireCompleteText { get; set; }
Property Value:

Determines if it is required to complete entered text in the RadMaskedTextBox. By default is 'false'. Set to 'true' if you want full text to be required.

Gets or sets if the caret will be moved to the begging when the RadMaskedTextBox is focused.

C#
[ClientControlProperty]
public bool ResetCaretOnFocus { get; set; }
Property Value:

Determines if the caret will be moved to the begging when the RadMaskedTextBox is focused.

Gets or sets if the numberic ranges will be rounded.

C#
[ClientControlProperty]
public bool RoundNumericRanges { get; set; }
Property Value:

Determines if the numberic ranges will be rounded.

Gets or sets the number of rows.

C#
public virtual int Rows { get; set; }
Property Value:

The number of rows.

Gets or sets the selection on focus options for the RadInput control

C#
[ClientControlProperty]
[Themeable(true)]
public override SelectionOnFocus SelectionOnFocus { get; set; }
Property Value:

A Telerik.WebControls.SelectionOnFocus object that represents the selection on focus in RadInput control. The default value is "None".

  • None
  • CaretToBeginning
  • CaretToEnd
  • SelectAll

Overrides: RadInputControl.SelectionOnFocus

Use this property to provide selection on focus of RadInput control. You can set one of the following values:

Example:
C#
</%@ Page Language="C#" /%>

</%@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="radI" /%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">

<title>RadTextBox selection</title>
<script runat="server">

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

if (DropDownList1.SelectedValue == "CaretToBeginning")
{

this.RadTextBox1.SelectionOnFocus = Telerik.WebControls.SelectionOnFocus.CaretToBeginning;

}
else if (DropDownList1.SelectedValue == "CaretToEnd")
{

this.RadTextBox1.SelectionOnFocus = Telerik.WebControls.SelectionOnFocus.CaretToEnd;

}
else if (DropDownList1.SelectedValue == "SelectAll")
{

this.RadTextBox1.SelectionOnFocus = Telerik.WebControls.SelectionOnFocus.SelectAll;

}
}
</script>
</head>
<body>

<form id="form1" runat="server">
<div>

<radI:RadTextBox SelectionOnFocus="CaretToBeginning" ID="RadTextBox1" runat="server"></radI:RadTextBox>

<br />

<asp:DropDownList AutoPostBack="true" ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

<asp:ListItem Text="CaretToBeginning">CaretToBeginning</asp:ListItem>

<asp:ListItem Text="CaretToEnd">CaretToEnd</asp:ListItem>

<asp:ListItem Text="SelectAll">SelectAll</asp:ListItem>

</asp:DropDownList></div>
</form>
</body>
</html>

Gets or sets the skin name for the control user interface.

C#
public override string Skin { get; set; }
Property Value:

A string containing the skin name for the control user interface. The default is string.Empty.

Overrides: RadInputControl.Skin

If this property is not set, the control will render using the skin named "Default". If EnableEmbeddedSkins is set to false, the control will not render skin.

C#
public virtual string SmartPasteDescription { get; set; }
C#
protected override HtmlTextWriterTag TagKey { get; }

Overrides: RadInputControl.TagKey

Gets or sets the text content of a control.

C#
public override string Text { get; set; }
Property Value:

The text content of a control.

Overrides: RadInputControl.Text

Gets or sets the text mode which could determine if the input will be multiline, password or normal single line input.

C#
public InputMode TextMode { get; set; }
Property Value:

The text mode which could determine if the input will be multiline, password or normal single line input.

Gets or sets the text including literals.

C#
[Browsable(true)]
public string TextWithLiterals { get; set; }
Property Value:

The text including literals.

Gets the text including the prompt.

C#
[Browsable(true)]
public string TextWithPrompt { get; }
Property Value:

The text including the prompt.

Gets the text with prompt and literals.

C#
[Browsable(true)]
public string TextWithPromptAndLiterals { get; }
Property Value:

The text with prompt and literals.

If the Wrap property is True, the value in the text box extends to the limit set by the Columns property, and then wraps to additional rows as necessary. If the Wrap property is False, the value in the text box does not wrap. Additional lines are used only if the text value includes a new-line character. A horizontal scroll bar appears if the value of any line exceeds the limit set by the Columns property.

C#
public virtual bool Wrap { get; set; }
Property Value:

If the Wrap property is True, the value in the text box extends to the limit set by the Columns property, and then wraps to additional rows as necessary. If the Wrap property is False, the value in the text box does not wrap. Additional lines are used only if the text value includes a new-line character. A horizontal scroll bar appears if the value of any line exceeds the limit set by the Columns property.

Gets or sets if the values of numeric range parts of the mask to have a fixed width.

C#
public bool ZeroPadNumericRanges { get; set; }
Property Value:

Enforces the values of numeric range parts of the mask to have a fixed width.

Methods

C#
protected override void AddAttributesToRender(HtmlTextWriter writer)
Parameters:writerHtmlTextWriter

Overrides: RadInputControl.AddAttributesToRender(HtmlTextWriter)

C#
protected override void AddParsedSubObject(object obj)
Parameters:objobject

Overrides: Control.AddParsedSubObject(object)

C#
protected override void DescribeClientEvents(IScriptDescriptor descriptor)
Parameters:descriptorIScriptDescriptor

Overrides: RadInputControl.DescribeClientEvents(IScriptDescriptor)

C#
protected override void DescribeClientProperties(IScriptDescriptor descriptor)
Parameters:descriptorIScriptDescriptor

Overrides: RadInputControl.DescribeClientProperties(IScriptDescriptor)

C#
protected override void DescribeComponent(IScriptDescriptor descriptor)
Parameters:descriptorIScriptDescriptor

Overrides: RadInputControl.DescribeComponent(IScriptDescriptor)

C#
protected override bool IsMultiLine()
Returns:

bool

Overrides: RadInputControl.IsMultiLine()

Loads the client state data

C#
protected override void LoadClientState(Dictionary<string, object> clientState)
Parameters:clientStateDictionary<string, object>

Overrides: RadInputControl.LoadClientState(Dictionary<string, object>)

C#
protected override void LoadViewState(object savedState)
Parameters:savedStateobject

Overrides: RadInputControl.LoadViewState(object)

C#
protected override void OnPreRender(EventArgs e)
Parameters:eEventArgs

Overrides: RadWebControl.OnPreRender(EventArgs)

C#
protected virtual void RefreshViewState()
C#
protected override void RenderContentsSingleInputFields(HtmlTextWriter writer)
Parameters:writerHtmlTextWriter

Overrides: RadInputControl.RenderContentsSingleInputFields(HtmlTextWriter)

C#
protected override void RenderTextAreaContents(HtmlTextWriter writer)
Parameters:writerHtmlTextWriter

Overrides: RadInputControl.RenderTextAreaContents(HtmlTextWriter)

C#
protected override object SaveViewState()
Returns:

object

Overrides: RadInputControl.SaveViewState()

C#
protected override void SetDefaultSize()

Overrides: RadInputControl.SetDefaultSize()

C#
protected override void TrackViewState()

Overrides: RadInputControl.TrackViewState()