asp.net
  • user-controls
  • webforms
  • asp.net-4.0
  • 2011-08-21 21 views 0 likes 
    0

    我在一份報告中標記的幾個部分看起來像這樣:如何構建一個使用標籤而不是屬性來設置屬性的UserControl?

    <div class="report-section span-24 last"> 
        <h3 class="section-header"> 
         Municipal Valuation</h3> 
        <p class="section-desc"> 
         <img src='<%= ResolveUrl("~/Images/info-icon.png")%>' class="left" alt="Section Description" /> 
         The <strong>Municipal Valuation</strong> is the valuation provided by the relevant 
         municipality and represents the market value assessed for rates purposes as at the 
         date of valuation.</p> 
    </div> 
    

    我想創建一個封裝一切,這是每個部分中的相同的用戶控件,這樣我可以代替定義我的部分像這樣:

    <lsReport:Section ID="reportDetails" runat="server" Title="Transfer Information"> 
        <Description>The <strong>Municipal Valuation</strong> is the valuation provided by the relevant 
        municipality and represents the market value assessed for rates purposes as at the 
        date of valuation.</Description> 
    </lsReport:Section> 
    

    使標題始終處於<h3 class="section-header">和描述的一段總是有圖像,等等。我怎麼去呢?我已經可以在控件的屬性中定義描述文本,但一些描述很長,並且包含標記。我想知道如何使用控件元素的Description子元素來設置控件的Description屬性。

    回答

    2

    我認爲你可以用自定義的模板用戶控件完成你正在做的事情。

    <uc:lstReport id="report1" Title="somevalue" runat="server">  
         <Description>  
          Some custom content you want rendered in the desc.  
         </Description>  
         <ItemTemplate>  
          Here is a calendar: <asp:calendar id="cal1" runat="server" />  
         </ItemTemplate>  
        </uc:lstReport> 
    

    查看this作爲首發的鏈接。

    +0

    感謝@coder,正確的方向步驟+1,但它看起來像我必須建立一個模板*服務器*控制,而不是用戶控制,以包括數據綁定在這種安排。 – ProfK

    相關問題