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 / Handle OnError Event

RadDateInput
Enter an invalid or predefined date:

Predefined dates
  • Today
  • Yesterday
  • Tomorrow
  • Christmas

  • This online demo presents how to handle the OnError client-side event of the RadDateInput to process some custom logic when the user enters invalid input or the date is out of range.

    For this case specifically we demonstrate replacing the invalid entry with a new date/corresponding date value from an array depending on whether the input is recognized as invalid/outside of the date range bounds.

    To test the aforementioned behavior you should enter one of the predefined strings (christmas, today, tomorrow or yesterday). Alternatively you can click on the bulleted list onto the right table directly.

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.RadDateInput.HandleErrorEvent.DefaultCS" %>

    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ 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 runat="server" ID="Headtag1"></qsf:HeadTag>
        <style type="text/css">
            .ulStyle li
            {
                border-bottom: solid 1px #eeeeee;
                margin-right: 30px;
                list-style-type: none;
                padding-left: 10px;
            }
            .rfdHeading h6
            {
                font-size: 8pt;
                font-weight: normal;
                margin: 0 0 0 0;
                padding-top: 10px;
            }
            .divBack
            {
                padding: 20px 0 20px 0;
            }
        </style>
    </head>
    <body class="BODY">
        <form id="Form1" method="post" runat="server">
        <qsf:Header runat="server" ID="Header1" NavigationLanguage="C#"></qsf:Header>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="Server" DecoratedControls="All"
            DecorationZoneID="decorationZone1" />
        <!-- content start -->
        <telerik:RadCodeBlock ID="RadCodeBloc1" runat="server">

            <script type="text/javascript">
                     //<![CDATA[
            function clearInput(sender, args)
            {
                $find('<%= RadDateInput1.ClientID %>').clear();
            }

            function Error(sender, args)
            {
                switch (args.get_reason())
                {
                    case Telerik.Web.UI.InputErrorReason.ParseError:
                        HandleDateParseError(sender, args.get_inputText().toUpperCase(), args);
                        break;
                    case Telerik.Web.UI.InputErrorReason.OutOfRange:
                        HandleDateOutOfRange(sender, args);
                        break;
                }
            }

            function trim(str)
            {
                return str.replace(/ /g, "");
            }

            function HandleDateParseError(radDateInput, inputText, args)
            {
                var now = new Date();

                args.set_cancel(true);

                var specialDays =
                             new Array(
                                     { DayName: "CHRISTMAS", Date: new Date(now.getFullYear(), 11, 25) },
                                     { DayName: "TODAY", Date: new Date() },
                                     { DayName: "TOMORROW", Date: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1) },
                                     { DayName: "YESTERDAY", Date: new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1) }
                                     );
                var i;
                for (i = 0; i < specialDays.length; i++)
                {
                    if (specialDays[i].DayName == trim(inputText).toUpperCase())
                    {
                        radDateInput.set_selectedDate(specialDays[i].Date);
                        break;
                    }
                }
            }

            function HandleDateOutOfRange(radDateInput, args)
            {
                args.set_cancel(true);
                radDateInput.set_selectedDate(new Date());
            }
                     //]]>
            </script>

        </telerik:RadCodeBlock>
        <div class="divBack" id="decorationZone1">
            <table style="margin: 0 auto; padding-left: 10px;">
                <tr>
                    <td style="padding: 10px; width: 50%">
                        <fieldset style="width: 220px; height: 110px; margin: 0 auto; padding: 0; text-align: center;">
                            <legend>RadDateInput </legend>
                            <div>
                                <h6>
                                    Enter an invalid or predefined date:</h6>
                                <div style="padding: 5px;">
                                    <telerik:RadDateInput ID="RadDateInput1" runat="server" ToolTip="Please enter an invalid or predefined date">
                                        <ClientEvents OnError="Error" />
                                    </telerik:RadDateInput>
                                </div>
                                <input type="button" onclick="clearInput()" value="Clear" />
                                <br />
                            </div>
                        </fieldset>
                    </td>
                    <td style="padding: 10px; width: 50%">
                        <fieldset style="width: 160px; height: 110px;">
                            <legend>Predefined dates</legend>
                            <div>
                                <ul class="ulStyle" style="margin-top: 0px; padding-top: 15px;">
                                    <li>Today</li>
                                    <li>Yesterday</li>
                                    <li>Tomorrow</li>
                                    <li>Christmas</li>
                                </ul>
                            </div>
                        </fieldset>
                    </td>
                </tr>
            </table>
        </div>
        <!-- content end -->
        <qsf:Footer runat="server" ID="Footer1"></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