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

Can't find Dynamically Created RadDatePicker in OnLoad

2 Answers 111 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 01 Mar 2014, 09:46 PM

I'm dynamically creating a RadDatePicker in the VB .NET code behind like so...

Dim oCalCell As New HtmlTableCell()
 
Dim oRadPicker As New Telerik.WebControls.RadDatePicker()
oRadPicker.ID = "cldrStageDate"
oRadPicker.Calendar.ID = "cldrStageDate_calendar"
oRadPicker.Calendar.ClientEvents.OnLoad = "cldrLoaded"
 
oCalCell.Controls.Add(oRadPicker)

Then on the client side I have the following javascript code:

function cldrLoaded(oCtl) {
   var sCtlId = null;
   if (typeof(oCtl.get_id) === "function") sCtlId = oCtl.get_id().split('_calendar')[0];
   else sCtlId = oCtl.ClientID; 
   var oCldr = $find(sCtlId);
}

The control is rendered on the page and appears to be working.  But inside "cldrLoaded",  oCtl doesn't have a function named "get_id" when this function is called, but it does have a "ClientID" set.  But the $find(sCtlID) won't find the RadDatePicker.

I have a DatePicker declared in the .aspx page that works as expected:

<telerik:RadDatePicker id="cldrStageDate" runat="server">
   <Calendar ID="cldrStageDate_calendar" runat="server">
      <ClientEvents OnLoad="cldrLoaded" />
   </Calendar>
</telerik:RadDatePicker>

How can I get the proper object get sent to the OnLoad function?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Mar 2014, 05:04 AM
Hi Daniel,

Please have a look into the sample code snippet which works fine at my end.

VB:
Protected Sub Page_Init(sender As Object, e As EventArgs)
    Dim radDatePicker1 As New Telerik.Web.UI.RadDatePicker()
    radDatePicker1.ID = "RadDatePicker1"
    radDatePicker1.Calendar.ClientEvents.OnLoad = "Load"
    Me.form1.Controls.Add(radDatePicker1)
End Sub

JavaScript:
<script type="text/javascript">
    function Load(sender, args) {
       //sender is the client side object to handle the control
    }
</script>

Thanks,
Shinu.
0
Daniel
Top achievements
Rank 1
answered on 03 Mar 2014, 12:31 PM
Hi Shinu,

Thank you for your comment and helpful solution!  Once I switched over to use the same object you did in your example, everything worked perfectly.

Dim radDatePicker1 As New Telerik.Web.UI.RadDatePicker()
Tags
Calendar
Asked by
Daniel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel
Top achievements
Rank 1
Share this question
or