Telerik RadInput exposes server-side API allowing the developer to customize RadDateInput, RadNumericTextBox, RadTextBox RadMaskedTextBox programmatically in code-behind.
RadDateInput
The extract of the source code below illustrates how you can customize an instance of RadDateInput programmatically in code-behind:
| C# |
Copy Code |
|
private void Page_Load(object sender, System.EventArgs e) { RadDateInput1.Culture = new CultureInfo("en-US"); RadDateInput1.DateFormat = "dd MMMM yyyy"; RadDateInput1.SelectedDate = DateTime.Now; } |
| VB.NET |
Copy Code |
|
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load RadDateInput1.Culture = New CultureInfo("en-US") RadDateInput1.DateFormat = "dd MMMM yyyy" RadDateInput1.SelectedDate = DateTime.Now End Sub |
RadNumericTextBox
The extract of the source code below illustrates how you can customize an instance of RadNumericTextBox programmatically in code-behind:
| C# |
Copy Code |
|
private void Page_Load(object sender, System.EventArgs e) { RadNumericTextBox1.Culture = new CultureInfo("en-US"); RadNumericTextBox1.Type = Telerik.WebControls.NumericType.Currency; RadNumericTextBox1.ShowSpinButtons = true; } |
| VB.NET |
Copy Code |
|
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load RadNumericTextBox1.Culture = new CultureInfo("en-US") RadNumericTextBox1.Type = Telerik.WebControls.NumericType.Currency RadNumericTextBox1.ShowSpinButtons = True End Sub |
RadTextBox
The extract of the source code below illustrates how you can customize an instance of RadNumericTextBox programmatically in code-behind:
| C# |
Copy Code |
|
private void Page_Load(object sender, System.EventArgs e) { RadTextBox1.TextMode = Telerik.WebControls.InputMode.MultiLine; RadTextBox1.EmptyMessage = "Type here"; RadTextBox1.MaxLength = 30; } |
| VB.NET |
Copy Code |
|
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load RadTextBox1.TextMode = Telerik.WebControls.InputMode.MultiLine RadTextBox1.EmptyMessage = "Type here" RadTextBox1.MaxLength = 30 End Sub |
RadMaskedTextBox
The extract of the source code below illustrates how to build the mask programmatically:
| C# |
Copy Code |
|
private void Page_Load(object sender, System.EventArgs e) { NumericRangeMaskPart rangePart = new NumericRangeMaskPart(); rangePart.LowerLimit = 0; rangePart.UpperLimit = 255; RadMaskedTextBox1.MaskParts.Add(rangePart); LiteralMaskPart literalPart = new LiteralMaskPart(); literalPart.Text = "."; RadMaskedTextBox1.MaskParts.Add(literalPart); } |
| VB.NET |
Copy Code |
|
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim rangePart As New NumericRangeMaskPart rangePart.LowerLimit = 0 rangePart.UpperLimit = 255 RadMaskedTextBox1.MaskParts.Add(rangePart) Dim literalPart As New LiteralMaskPart literalPart.Text = "." RadMaskedTextBox1.MaskParts.Add(literalPart) End Sub |
All controls provide OnTextChanged server event which will be raised when the AutoPostBack property of the corresponding RadInput control is set to true, the user types valid entry and the input loses focus.
The postback request can be cancelled (for RadDateInput, RadNumericTextBox and RadTextBox) hooking the OnValueChanged client event of the input and returning false from its handler.
| [ASPX/ASCX] |
Copy Code |
|
<script type="text/javascript"> function ValueChanged(sender, e) { //return false here if you would like to cancel a postback request } </script>
<rad:RadTextBox id="RadTextBox1" runat="server"> <ClientEvents OnValueChanged="ValueChanged" /> <rad:RadTextBox> <%-- The same event can be wired for the RadNumericTextBox or RadDateInput --%> |
| VB.NET |
Copy Code |
|
Protected Sub RadTextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadTextBox1.TextChanged End Sub |
| C# |
Copy Code |
|
protected void RadTextBox1_TextChanged(object sender, System.EventArgs e) { //execute custom logic here //the same event can be handled for the rest of the input controls } |
See Also