Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Input / Error Handling


RadNumericTextBox:
RadMaskedTextBox:
RadDateInput:
Control Name Input Error Message
RadNumericTextBox
RadMaskedTextBox
RadDateInput


  • The RadMaskedTextBox and RadNumercTextBox are configured to accept only digits. Try entering some letters. The RadDateInput accepts only month/day names and numbers.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" AutoEventWireup="false" Inherits="Telerik.InputExamplesCS.Programming.ClientSide.OnError.DefaultCS" %>

    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server"></qsf:HeadTag>
        <!-- custom head section -->
        <style type="text/css">
            .DivStyle
            {
                float: left;
                margin-bottom: 10px;
            }
        </style>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
        <!--
                function onError(input, args) {
                    var message = "Invalid character: ";
                    switch (input.get_id()) {
                        case "RadNumericTextBox1":
                            message += "accepts only numberic values.";
                            document.getElementById("numInput").innerHTML = args.get_inputText();
                            document.getElementById("numErrorOut").innerHTML = message;
                            break;
                        case "RadMaskedTextBox1":
                            message += "the value <b>" + args.get_newValue() + "</b> is not numeric.";
                            document.getElementById("maskInput").innerHTML = args.get_newValue();
                            document.getElementById("maskErrorOut").innerHTML = message;
                            break;
                        case "RadDateInput1":
                            message += "the value <b>" + args.get_inputText() + "</b> is not a valid date time argument(s).";
                            document.getElementById("dateInput").innerHTML = args.get_inputText();
                            document.getElementById("dateErrorOut").innerHTML = message;
                            break;
                        default: break;
                    }
                }
                function onKeyPress(input, args) {
                    switch (input.get_id()) {
                        case "RadNumericTextBox1":
                            document.getElementById("numInput").innerHTML = "";
                            document.getElementById("numErrorOut").innerHTML = "";
                            break;
                        case "RadMaskedTextBox1":
                            document.getElementById("maskInput").innerHTML = "";
                            document.getElementById("maskErrorOut").innerHTML = "";
                            break;
                        case "RadDateInput1":
                            document.getElementById("dateInput").innerHTML = "";
                            document.getElementById("dateErrorOut").innerHTML = "";
                            break;
                        default: break;
                    }
                }
        -->
            </script>
        </telerik:RadCodeBlock>
        <!-- end of custom head section -->
    </head>
    <body class="BODY">
        <form id="mainForm" method="post" runat="server">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="C#"></qsf:Header>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <!-- content start -->
        <br />
        <div class="module DivStyle" style="width: 28%">
            RadNumericTextBox:
            <br />
            <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Type="Number">
                <ClientEvents OnError="onError" OnKeyPress="onKeyPress"></ClientEvents>
            </telerik:RadNumericTextBox>
        </div>
        <div class="module DivStyle" style="width: 28%">
            RadMaskedTextBox:
            <br />
            <telerik:RadMaskedTextBox ID="RadMaskedTextBox1" runat="server" PromptChar="_" Mask="(###) ###-#####">
                <ClientEvents OnError="onError" OnKeyPress="onKeyPress" />
            </telerik:RadMaskedTextBox>
        </div>
        <div class="module DivStyle" style="width: 28%">
            RadDateInput:
            <br />
            <telerik:RadDateInput ID="RadDateInput1" runat="server" DateFormat="dd MMM yy hh:mm:ss tt">
                <ClientEvents OnError="onError" OnKeyPress="onKeyPress"></ClientEvents>
            </telerik:RadDateInput>
        </div>
        <div class="module" style="width: 688px; clear: both;">
            <table cellpadding="4" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <td style="width: 23%">
                            <b>Control Name</b>
                        </td>
                        <td style="width: 22%">
                            <b>Input</b>
                        </td>
                        <td style="width: 55%">
                            <b>Error Message</b>
                        </td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td valign="top">
                            RadNumericTextBox
                        </td>
                        <td>
                            <span id="numInput"></span>
                        </td>
                        <td>
                            <span id="numErrorOut" style="color: Red"></span>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            RadMaskedTextBox
                        </td>
                        <td>
                            <span id="maskInput"></span>
                        </td>
                        <td>
                            <span id="maskErrorOut" style="color: Red"></span>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            RadDateInput
                        </td>
                        <td>
                            <span id="dateInput"></span>
                        </td>
                        <td>
                            <span id="dateErrorOut" style="color: Red"></span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <br />
        <!-- content end -->
        <qsf:Footer ID="Footer1" runat="server"></qsf:Footer>
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451