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

Creating RadDateTimePicker dynamically

2 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Norman
Top achievements
Rank 1
Norman asked on 22 Dec 2014, 05:03 PM
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 Answers, 1 is accepted

Sort by
0
Norman
Top achievements
Rank 1
answered on 22 Dec 2014, 05:47 PM
Sorry I sorted this - I should have set the value after I added the control to the page. All works fine now.
0
Eyup
Telerik team
answered on 25 Dec 2014, 08:22 AM
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.

 
Tags
General Discussions
Asked by
Norman
Top achievements
Rank 1
Answers by
Norman
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or