2008-10-09 20 views
0

在頁面上,在加載事件中,我動態地創建控件以在頁面上顯示。這一切都正常工作。我遇到的麻煩是從AJAX控件工具包中添加擴展器,特別是我試圖向按鈕控件添加圓角。沒有錯誤被拋出,但AJAX擴展功能沒有出現在顯示的頁面中。我可以通過編程方式(服務器端)將ASP.NET AJAX擴展添加到頁面嗎?

有沒有人有任何想法,我沒有做得對,或者如果它甚至有可能?

Dim container As HtmlGenericControl 
Dim edit As Button 
Dim editRoundedCorners As AjaxControlToolkit.RoundedCornersExtender 

For each item in items 
      container = New HtmlGenericControl("div") 
      container.ID = "container_" & item.code 

      edit = New Button() 
      edit.ID = "edit_" & item.code 
      edit.Text = "Edit" 
      edit.Style("padding") = "0 0 0 4px" 
      edit.SkinID = "smallEditButton" 

      editRoundedCorners = New AjaxControlToolkit.RoundedCornersExtender() 
      editRoundedCorners.BorderColor = edit.BorderColor 
      editRoundedCorners.ID = edit.ID & "_RoundedCorners" 
      editRoundedCorners.Corners = AjaxControlToolkit.BoxCorners.All 
      editRoundedCorners.Radius = 3 
      editRoundedCorners.TargetControlID = edit.ID 

      container.Controls.Add(editRoundedCorners) 
      container.Controls.Add(edit) 
      pageContainer.Controls.Add(container) 
Next 

(pageContainer是頁面上的一個div)

回答

1

您不能應用RoundedCornersExtender來輸入元素,如文本框或按鈕。

2

您需要添加 「editRoundedCorners」 頁面,或容器控件集合,所以嘗試添加一行:

Controls.Add(editRoundedCorners) 

就在「將它們添加到頁面控件集合」之前,因爲您只能添加編輯按鈕,而兩者都是必需的。

+0

我修改了我的示例以包含我用來添加到頁面的方式。 (實際上有一個用循環構建的HTML表格,但爲簡單起見,我沒有包含它。) 這是你的意思嗎? – StingyJack 2008-10-09 12:38:20

+0

我已經添加了控件的次數,但是*不是*控件集合的擴展器 - 它值得檢查=) – Rob 2008-10-09 12:41:45

2

我正在使用C#,所以我將使用該語法。

正如Rob所說,您需要將Extender添加到頁面中。你可以這樣做的:

*parentCtrl*.Controls.Add(*extendername*); 

,或者

*controltype* *controlname* = (*controltype*)Page.LoadControl(typeof(*controltype*), new object[]{}); 

如果你在傳遞參數的控制,把他們的對象數組英寸

+0

嗨, 所以您應該將擴展器控件添加到TargetControl的控件集合中? 我也發現其他擴展(模態等)沒有問題。它只是圓角。 – StingyJack 2008-10-13 18:29:25

相關問題