Creating RadDateTimePicker dynamically

3 posts, 0 answers
  1. Norman
    Norman avatar
    3 posts
    Member since:
    Feb 2013

    Posted 22 Dec 2014 Link to this post

    Hi,

    I have a requirement to create a number of server controls (e.g. asp textboxes etc.) as well as RadDateTimePickers dynamically (e.g. at runtime) on a webform. I'm using the same approach to create instances of both types of control (see below):

    TextBox txt = new TextBox();
    txt.ID = "someid"
    txt.CssClass = "my-textbox-class";
    ph.Add(txt); //add to placeholder control
     
    RadDateTimePicker dtp = new RadDateTimePicker();
    dtp.ID = "adifferentid";
    dtp.Width = new Unit(200, UnitType.Pixel);
    dtp.DateInput.CssClass = "my-datepicker-class";
    dtp.TimeView.Interval = new TimeSpan(0, 30, 0);
    dtp.TimeView.Columns = 6;
    ph.Add(dtp); //add to placeholder control

    Because they're created dynamically I recreate the controls every time there is a postback. I've noted that the regular asp controls maintain any values entered into them automatically after they're recreated however the RadDateTimePickers don't. Is there something I'm missing?

    Thanks

  2. Norman
    Norman avatar
    3 posts
    Member since:
    Feb 2013

    Posted 22 Dec 2014 Link to this post

    Sorry I sorted this - I should have set the value after I added the control to the page. All works fine now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 25 Dec 2014 Link to this post

    Hello Norman,

    I just want to remind you that the controls should be created in the Page_Init handler in order for their server events to work properly.

    Hope this helps.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top