2012-03-23 29 views
1

我在尋找2天來完成以下任務: 我想要一個自定義控件,它將採用內聯文本+代碼塊。asp.net自定義控件中的代碼塊+文字

什麼,我想實現舉例:

<asp:MyCustom runat="server"> 
    Hello there, <%= User.Name%> 
</asp:MyCustom> 

這是我目前有:

[ParseChildren(true), PersistChildren(true)] 
public class MyCustom 
{ 
    [PersistenceMode(PersistenceMode.InnerDefaultProperty)] 
    public ITemplate Text { get; set; } 

    //Constructor 
    public MyCustom() 
    { 
     Text = new StringITemplate(text); 
    } 
} 

最重要的是,控制實際上是一個父列表中的一員從「UserControl」繼承的用戶控件將覆蓋Render方法。此外,還有一個類StringITemplate,它允許將純字符串分配給ITemplate屬性。

最後,我要實現以下目標:

<asp:MyCustomItemControl runat="server"> 
    <Items> 
     <asp:Item>Hello there, <%= User.Name%></asp:Item> 
     <asp:Item><%= SomeOtherString%></asp:Item> 
    </Items> 
</asp:MyCustom> 

現在,我會很高興,如果我的第一個請求實際工作。看起來像地獄來抓住網站/用戶/自定義/服務器的荒野 - asp.net及其屬性中的控件。

什麼,我已經把現在,可以在這裏看的完整代碼: http://pastebin.com/3gic2Y0u

感謝您閱讀:)

回答