使用内部html创建自定义控件的最简单方法是什么?

时间:2014-05-08 10:45:55

标签: c# html asp.net web-controls

我有一个带有几个控件的* .aspx页面,其中一个是Lightbox。灯箱的代码如下:

public partial class Lightbox : System.Web.UI.UserControl
{
    public string Header { get; set; }
    public string CloseLink { get; set; }
    public string Body { get; set; }
    public string CssClass { get; set; }
    public bool ShowModalRedirect { get; set; }
    public string ModalName { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.DataBind();
        }
    }
}

ASPX:

<div id='<%=ModalName%>' class="modal hide fade <%= CssClass %>">
    <div class="modal-header">
        <asp:HyperLink ID="closePopup" CssClass="close" runat="server" >&times;</asp:HyperLink>
        <h3>
            <asp:Literal ID="header" Text='<%# Header %>' runat="server" />
        </h3>
    </div>
    <div class="modal-body">
        <asp:Literal ID="body" Text='<%# Body %>'  runat="server" />
    </div>
</div>
    <%
    if (ShowModalRedirect) {
        %>
        <a href="<%= CloseLink %>" id="my-modal-redirect" class="link-fade-invisible" style="display: none;"></a>
    <% } %>

目前,它在名为main.aspx的页面中以下列方式使用:

<block:Lightbox ID="productsLightbox" CloseLink="<%# ProductsUri %>" ModalName="mymodal-discounts" CssClass="modal-discounts" ShowModalRedirect="true" runat="server" ></block:Lightbox>

Lightbox的Header和Body属性(可以是HTML字符串)填充在main.aspx的代码隐藏中。我希望释放该责任背后的代码,并能够做到以下几点:

<block:Lightbox ID="productsLightbox" CloseLink="<%# ProductsUri %>" ModalName="mymodal-discounts" CssClass="modal-discounts" ShowModalRedirect="true" runat="server" >
    <div>Any HTML here</div>
</block:Lightbox>

我希望内部HTML成为我控制的主体。我怎样才能做到这一点?有没有办法同时为标题和正文做同样的事情?

谢谢

0 个答案:

没有答案