RadDatePicker Clearing Problem

3 posts, 0 answers
  1. Renan
    Renan avatar
    12 posts
    Member since:
    Jun 2008

    Posted 07 Apr 2012 Link to this post

    Hi All,

    We are having some difficulties on clearing RadDatePicker selected values. We have multiple RadDatePicker on our page and we want to clear its selected date to NULL or empty its input box, we already tried filtering RadDatePicker, DatePickingInput and RadDateInput with no success.

    "No problem on JavaScript but we need to do it on server side"

    Sample Code:

    public void ResetFormControlValue(Control parent)
    {
        foreach (Control c in parent.Controls)
        {
            if (c.Controls.Count > 0)
            {
                ResetFormControlValue(c);
            }
            else
            {
                switch (c.GetType().ToString())
                {
                    case "Telerik.Web.UI.RadNumericTextBox":
                        break;
                    case "Telerik.Web.UI.RadTextBox":
                        break;
     
                    case "Telerik.Web.UI.DatePickingInput": // Clear all RadDatePicker
                        ((RadDateInput)c).Clear();
                        break;
                }
            }
        }
    }

    Thanks for any help!


  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Apr 2012 Link to this post

    Hello Renan,

    Try clearing the DatePicker using its ID.
    C#:
    case:Telerik.Web.UI.RadDatePicker:
    RadDatePicker1.Clear();

    Thanks,
    Princy.
  3. Renan
    Renan avatar
    12 posts
    Member since:
    Jun 2008

    Posted 09 Apr 2012 Link to this post

    Hi Princy,

    Thank you for your reply. What i did is to get the control ID and use FindControl(). In this way, I am not tied on specific control name, because, we have Nth DapePicker on our page.

    Again, thanks for your response.

    Final Code:
    public void ResetFormControlValue(Control parent)
        {
            foreach (Control c in parent.Controls)
            {
                if (c.Controls.Count > 0)
                {
                    ResetFormControlValue(c);
                }
                else
                {
                    switch (c.GetType().ToString())
                    {
                        case "Telerik.Web.UI.RadNumericTextBox":
                            ((RadNumericTextBox)c).Value = 0;
                            break;
                        case "Telerik.Web.UI.RadTextBox":
                            ((RadTextBox)c).Text = "";
                            break;
                        case "System.Web.UI.WebControls.TextBox":
                            ((TextBox)c).Text = "";
                            break;
                        case "Telerik.Web.UI.RadComboBox":
                            ((RadComboBox)c).SelectedIndex = 0;
                            break;
                        case "Telerik.Web.UI.RadComboBoxItem":
                            ((RadComboBoxItem)c).ComboBoxParent.SelectedIndex = 0;
                            break;
                        case "System.Web.UI.WebControls.CheckBox":
                            ((CheckBox)c).Checked = false;
                            break;
                        case "Telerik.Web.UI.RadMaskedTextBox":
                            ((RadMaskedTextBox)c).Text = "";
                            break;
      
                       case "Telerik.Web.UI.DatePickingInput":
                            var rdp = FindControl((c).NamingContainer.ID);
                            ((RadDatePicker)(rdp)).Clear();
                            break;
                    }
                }
            }
        }
Back to Top