【问题标题】:How can I build a UserControl that uses tags instead of attributes to set properties?如何构建使用标签而不是属性来设置属性的 UserControl?
【发布时间】:2011-08-22 01:16:29
【问题描述】:

我在报告中有几个标记部分,如下所示:

<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>

所以标题总是在&lt;h3 class="section-header"&gt; 中,描述段落总是有图像等。我该怎么做?我已经可以在控件的属性中定义描述文本,但是有些描述很长,并且包含标记。我想知道如何使用控件元素的描述子元素来设置控件的描述属性。

【问题讨论】:

    标签: asp.net user-controls webforms asp.net-4.0


    【解决方案1】:

    我认为您可以使用自定义模板用户控件完成您想要做的事情。

    <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 链接。

    【讨论】:

    • 感谢@coder,+1 朝着正确的方向迈出了一步,但看起来我必须构建一个模板化的 server 控件,而不是用户控件,以包含数据绑定在这种安排中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    相关资源
    最近更新 更多