2009-11-20 112 views
2

我有一個如下問題: 我有一個頁面,我需要從後面的代碼動態地創建大量元素。它顯然取決於從數據庫傳遞的內容,但元素的數量可能會發生變化,這就是爲什麼我無法做到靜態。ASP.NET AJAX工具包CalendarExtender不工作C#

我在看什麼,就是:

我已經靜態創建PANEL:

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

然後在後面的代碼,我創建其他控件,並將其添加到我的標籤。問題我有是,點擊後iEditStartDateCalendar應該出現的CalendarExtender不彈出:(我看不到我在做什麼錯在這裏?任何幫助嗎?!?!

// StartDate 
Label lStartDateSite = new Label(); 
pFullInfo_lStartDateStr.Controls.Add(lStartDateSite); 

Label lStartDate = new Label(); 
pFullInfo_lStartDateStr.Controls.Add(lStartDate); 

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

TextBox tbEditStartDate = new TextBox(); 
pFullInfo_lStartDateStr.Controls.Add(tbEditStartDate); 

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

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

回答

1

通常,在標記中添加日曆擴展程序時,您只需將PopupButtonIDTargetControlID設置爲這些控件的ID,而不是UniqueID

時動態添加的東西如標籤,你AssociatedControlID設置爲控制,而不是UniqueID/ClientIDID和框架的作品出來的渲染時間。

另外,大多數JavaScript庫更喜歡使用控件的實際id,而不是name屬性,所以應該使用ClientID來代替。

1

我發現。該解決方案 問題是用「的UniqueID」我是路過 正確的解決辦法是在這裏:。


// StartDate 
Label lStartDateSite = new Label(); 
pFullInfo_lStartDateStr.Controls.Add(lStartDateSite); 

Label lStartDate = new Label(); 
pFullInfo_lStartDateStr.Controls.Add(lStartDate); 

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

TextBox tbEditStartDate = new TextBox(); 
pFullInfo_lStartDateStr.Controls.Add(tbEditStartDate); 
tbEditStartDate.ID = "tbEditStartDate_" + this_site_id; 

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

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

所以我做了什麼basicaly,我分配一個ID對它們被用於文本框和圖像日曆,並工作:] 非常感謝堆棧溢出:]