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

[Solved] Applying Telerik DatePicker Dynamically

3 Answers 190 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
adeel zahid
Top achievements
Rank 1
adeel zahid asked on 15 Jul 2011, 07:32 AM
Hello Everyone,
i have a scenario where i have to add fields dynamically on the page through javascript. How can i apply telerik datepicker to dynamically added fields.
regards

3 Answers, 1 is accepted

Sort by
0
Igniter
Top achievements
Rank 1
answered on 12 Aug 2011, 07:32 AM

I have created PartialViews, for example DateTime one:
@Html.Telerik().DateTimePicker().Name(ViewData["PickerName"].ToString())

And to add the control dynamically on the page through javascript call controller, post the name of conrol you want to add, and controller will return you partialview (html), which you will insert where you like:
public ActionResult LoadEditTemplate(string controlName)
        {          
            ViewData["PickerName"] = controlName;                
            return PartialView("Date");
        }

function addControl(name) {
            $("#divToInjectControlTo").load('@Url.Action("LoadEditTemplate", "TheController")', { controlName: name });
        }

0
adeel zahid
Top achievements
Rank 1
answered on 12 Aug 2011, 10:48 AM
Alex, 
Thanks for the input. I have solved this problem by using client side library of Telerik. Like i would add a blank input field to the page and call tDatePicker method which will turn it into a telerik date picker like

$('tr.editorRow:last .telerik-dp').tDatePicker({ format: 'dd/MM/yyyy'});
There are similar methods like tAutoComplete and tComboBox for different telerik controls
0
Mahesh
Top achievements
Rank 1
answered on 06 Apr 2012, 12:47 PM
Hi,
I have a scenario where i have to add  date picker dynamically and i have to add the events like onChange to that datepicker.How can i make it possible?

Regards
Tags
General Discussions
Asked by
adeel zahid
Top achievements
Rank 1
Answers by
Igniter
Top achievements
Rank 1
adeel zahid
Top achievements
Rank 1
Mahesh
Top achievements
Rank 1
Share this question
or