This is a migrated thread and some comments may be shown as answers.

RadDatePicker - preserve invalid data entry on postback?

1 Answer 85 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Robert Columbia
Top achievements
Rank 1
Robert Columbia asked on 25 Aug 2010, 06:09 PM
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?

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 26 Aug 2010, 01:27 PM
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;
            }
        }
    }
     
</script>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<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">
 
Sys.Application.add_load(populatePicker);
 
function populatePicker()
{
    var invalidValue = $get("<%= HiddenField1.ClientID %>").value;
    if (invalidValue != "")
    {
        var picker = $find("<%= RadDatePicker1.ClientID %>");
        picker.get_dateInput().set_value(invalidValue);
        picker.get_textBox().value = invalidValue;
    }
}
 
</script>
</telerik:RadCodeBlock>
 
</form>
</body>
</html>


Kind regards,
Dimo
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
Tags
Calendar
Asked by
Robert Columbia
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or