Adding RadDateTimePicker dynamically.

4 posts, 0 answers
  1. jayakumar chinnappa
    jayakumar chinnappa avatar
    2 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2010 Link to this post

    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



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

    Posted 15 Jan 2010 Link to this post

    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.
  3. jayakumar chinnappa
    jayakumar chinnappa avatar
    2 posts
    Member since:
    Jan 2010

    Posted 18 Jan 2010 Link to this post

    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..



  4. Martin
    Admin
    Martin avatar
    833 posts

    Posted 21 Jan 2010 Link to this post

    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.
Back to Top