RadDatePicker - preserve invalid data entry on postback?

2 posts, 0 answers
  1. Robert Columbia
    Robert Columbia avatar
    14 posts
    Member since:
    Jun 2012

    Posted 25 Aug 2010 Link to this post

    I have a "bug report" where they are complaining that when you enter invalid/non-parsable data (such as "oapsd") via the keyboard into a RadDatePicker or a RadTimePicker, the invalid input does not persist on postback.  They wanted the invalid input to be preserved for the user to correct upon explicit prodding, rather than clearing it for them and asking them to do it over again.

    Is this something we can do easily?
  2. Dimo
    Dimo avatar
    8485 posts

    Posted 26 Aug 2010 Link to this post

    Hello Robert,

    You can achieve the desired behavior as demonstrated below. Although you should not have any problems, keep in mind that this approach is technically a hack.

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
            if (IsPostBack)
                if (RadDatePicker1.SelectedDate == null && !String.IsNullOrEmpty(RadDatePicker1.ValidationDate))
                    HiddenField1.Value = RadDatePicker1.ValidationDate;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="Submit" />
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
    function populatePicker()
        var invalidValue = $get("<%= HiddenField1.ClientID %>").value;
        if (invalidValue != "")
            var picker = $find("<%= RadDatePicker1.ClientID %>");
            picker.get_textBox().value = invalidValue;

    Kind regards,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top