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

[Solved] RadDateTimePicker can't be manipulated at initial load?

1 Answer 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy F.
Top achievements
Rank 1
Iron
Andy F. asked on 22 Jun 2008, 07:31 PM
I have a grid using an EditForm to edit the records.  The EditForm has a RadComboBox (cmbDateChoice) and a RadDateTimePicker (dateParameter).  Let's say the values in the RadComboBox are A, B, C.  When the value is A, I want to enable the RadDateTimePicker, when it's B or C, I want to disable it.  The grid has ALL rows set to be in edit mode via ItemCreated.

    protected void gridParameters_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridEditableItem)  
        {  
            e.Item.Edit = true;  
            if (e.Item is GridEditFormItem)  
            {  
                Telerik.Web.UI.GridEditFormItem editForm = e.Item as Telerik.Web.UI.GridEditFormItem;  
                RadDateTimePicker dateParameter = (RadDateTimePicker)editForm.FindControl("dateParameter");  
                RadComboBox cmbDateChoice = (RadComboBox)editForm.FindControl("cmbDateChoice");  
 
                if ((cmbDateChoice != null) && (dateParameter != null))  
                {  
                    string fields = "<script type='text/javascript' language='javascript'>";  
                    fields += "function " + cmbDateChoice.ClientID + "_change() { ";  
                    fields += "return ChangeDatePicker($find(\"" + cmbDateChoice.ClientID + "\"), $find(\"" + dateParameter.ClientID + "\"));";  
                    fields += "}";  
                    fields += "</script" + ">";  
 
                    gridParameters.Controls.Add(new LiteralControl(fields));  
                    cmbDateChoice.OnClientSelectedIndexChanged = cmbDateChoice.ClientID + "_change";  
                }  
            }  
        }  
    } 

And this is the javascript function to manipulate the DateTimePicker:
        function ChangeDatePicker(choices, picker)  
        {  
            if (choices.get_value() == "A")  
            {  
                picker.get_dateInput().enable();  
                $addHandler(picker.get_popupButton(), "click", picker._onPopupButtonClickDelegate);  
                if (window[picker.get_id()] != null)  
                {  
                    picker._onTimePopupImageClickDelegate = window[picker.get_id()];  
                    $addHandler(picker.get__timePopupImage(), "click"window[picker.get_id()]);  
                }  
            }  
            else 
            {  
                picker.get_dateInput().disable();  
                $removeHandler(picker.get_popupButton(), "click", picker._onPopupButtonClickDelegate);  
                $removeHandler(picker.get__timePopupImage(), "click", picker._onTimePopupImageClickDelegate);  
                window[picker.get_id()] = picker._onTimePopupImageClickDelegate;  
                picker._onTimePopupImageClickDelegate = null;  
            }  
                  
            return true;  
        } 

When the combo box changes its index, all works perfectly.  However, I can't find the right combination of code to get it to fire when the combobox is first initialized.  In other words, if I come into the grid with a combobox value of B, I want the javascript to fire to change the DateTimePicker to disabled.  I tried attaching the code to the OnClientLoad event on the combobox, but for some reason the DateTimePicker doesn't exist at that point (the $find returns null).

Any suggestions on how to go about this?  Thanks.

1 Answer, 1 is accepted

Sort by
0
Missing User
answered on 26 Jun 2008, 08:21 AM
Hi Andy,

You can use RadDateTimePicker.DateInput.ClientEvents.OnLoad event handler. The OnLoad client-side event handler is called when the input control is loaded on the client.

Two parameters are passed to the event handler:
  • sender is the input control.
  • eventArgs is an instance of Sys.EventArgs.
Let us know whether this helps.

Regards,
Plamen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Andy F.
Top achievements
Rank 1
Iron
Answers by
Missing User
Share this question
or