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

Adding RadDateTimePicker dynamically.

3 Answers 168 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
jayakumar chinnappa
Top achievements
Rank 1
jayakumar chinnappa asked on 15 Jan 2010, 12:23 PM
Hi Team,

the first issue i am facing is how do i add the RadDateTimePicker dynamically from the code behind. I tried putting the control using the following piece of snippet.
 cntrlType = webControls.GetType("Telerik.Web.UI.RadDateTimePicker");
                            objCntrl = Activator.CreateInstance(cntrlType);
                            ((Telerik.Web.UI.RadDateTimePicker)objCntrl).ID="datetimePicker";
                            this.Controls.Add((Telerik.Web.UI.RadDateTimePicker)objCntrl);
after adding this from the code behind it is displaying the date and time button, however on clik of those button no go.
Kindly help us.

thanks,
jayakumar chinnappa



3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jan 2010, 01:42 PM
Hello Jayakumar,

If you are creating the RadDatePicker dynamically in another control event such as a button, then you can store a value in the ViewState on the button click once the control is created.
protected void Button1_Click(object sender, EventArgs e) 
    { 
          // create datepicker 
          ViewState["control"] = "ControlAdded"// setting a flag 
    } 

Then in the Page_Init event, you can check for the ViewState value and then recreate the control again:
protected void Page_Init(object sender, EventArgs e) 
    { 
        if (ViewState["control"] != null
        { 
            if (ViewState["control"].ToString() == "ControlAdded"
            { 
                //create datepicker 
            } 
        } 
    } 

Thanks
Princy.
0
jayakumar chinnappa
Top achievements
Rank 1
answered on 18 Jan 2010, 01:19 PM
i am trying to create the controls in the page load  event of the page as
cntrlType = webControls.GetType("Telerik.Web.UI.RadDatePicker");
objCntrl = Activator.CreateInstance(cntrlType);
((Telerik.Web.UI.RadDatePicker)objCntrl).ID = "datetimePicker";
this.Controls.Add((Telerik.Web.UI.RadDatePicker)objCntrl);

it is displaying only the calendar and time icons but nothing is happening on click of those icons.
i tried doing the changes specified by princy still nothing is happening...... could u please post a working page or a solution..



0
Martin
Telerik team
answered on 21 Jan 2010, 09:36 AM
Hello Jayakumar,

I would suggest you to modify your code like this:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
    <asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>

Code-behind:

protected void Page_Init(Object sender, EventArgs e)
   {
       object objCntrl = Activator.CreateInstance(typeof(RadDatePicker));
       ((Telerik.Web.UI.RadDatePicker)objCntrl).ID = "datetimePicker";
       PlaceHolder1.Controls.Add((Telerik.Web.UI.RadDatePicker)objCntrl);
   }


I hope this helps,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Calendar
Asked by
jayakumar chinnappa
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
jayakumar chinnappa
Top achievements
Rank 1
Martin
Telerik team
Share this question
or