R – ASP.NET AJAX Toolkit CalendarExtender not working C#


I have a folowing problem:
I have a page where I need to create a lot of elements dynamically from the code behind. It obviously depends on what is passed from the database, but the number of elements can change, that's why I cannot do it static.

What I have at the moment, is:

I have statically created PANEL:

<asp:Panel ID="pFullInfo_lStartDateStr" runat="server"></asp:Panel>

Then in Code Behind, I'm creating other Controls and add them to my Label. The Issue I have is that the CalendarExtender that should appear after clicking the iEditStartDateCalendar doesn't popup 🙁 I can't see what I'm doing wrong here ? Any help please ?!?!

// StartDate
Label lStartDateSite = new Label();

Label lStartDate = new Label();

ImageButton ibEditStartDate = new ImageButton();
ibEditStartDate.ID = "ibEditStartDate_" + this_site_id;

TextBox tbEditStartDate = new TextBox();

Image iEditStartDateCalendar = new Image();
iEditStartDateCalendar.ID = "iEditStartDateCalendar";
iEditStartDateCalendar.ImageUrl = "~/i/small/calendar.png";
iEditStartDateCalendar.ImageAlign = ImageAlign.AbsMiddle;

CalendarExtender ceEditStartDate = new CalendarExtender();
ceEditStartDate.ID = "ceEditStartDate_" + this_site_id;
ceEditStartDate.PopupButtonID = iEditStartDateCalendar.UniqueID;
ceEditStartDate.TargetControlID = tbEditStartDate.UniqueID;
ceEditStartDate.PopupPosition = CalendarPosition.Right;

Best Solution

Normally, when adding the calendar extender in markup, you'd just set the PopupButtonID and TargetControlID to the ID of those controls, not the UniqueID.

When adding things like Labels dynamically, you set the AssociatedControlID to the ID of the control, not the UniqueID/ClientID and the framework works it out at render time.

Also, most JavaScript libraries prefer you to use the actual id of the control, rather than the name attribute, so you should use ClientID instead.

Related Question