Telerik ASP.NET AJAX – Giving focus to a DatePicker after AJAX callback.

I had a form with three Telerik DatePickers controls and had enabled postback on the first two to perform some server-side work.  The sample code attached is just setting the minimum date for the other DatePickers on the form.  After returning from postback, I expected the next DatePicker to have focus, but I could not get it to happen.  I sent the Telerik support team a message asking for help and the solution came quick and was very simple:

    protected void RadDatePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
    {
        if (e.NewDate.HasValue)
        {
            RadDatePicker2.MinDate = e.NewDate.Value;
            RadDatePicker3.MinDate = e.NewDate.Value;
            RadAjaxManager1.FocusControl(RadDatePicker2.DateInput.ClientID + "_text");
        }
    }

    protected void RadDatePicker2_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
    {
        if (e.NewDate.HasValue)
        {
            RadDatePicker3.MinDate = e.NewDate.Value;
            RadAjaxManager1.FocusControl(RadDatePicker3.DateInput.ClientID + "_text");
        }
    }
Facebooktwittergoogle_plusredditpinterestlinkedinmailFacebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Leave a Reply

Your email address will not be published. Required fields are marked *