gpt4 book ai didi

asp.net - 在 asp.net UserControl 上公开嵌套的 HTML 属性

转载 作者:行者123 更新时间:2023-12-02 15:49:48 24 4
gpt4 key购买 nike

我有一个 asp.net UserControl,它将 HTML 内容从 SharePoint 列表写入 Literal 控件。目前,我在写入 Literal 的每个 SharePoint 列表项之前在 h5 标记中插入标题。我不想将标题硬编码放置在 h5 标记中,而是想公开用户控件的公共(public)属性,让我定义标题的 html 格式。这与我发现的很多模板化用户控件问题有点不同,因为它并不是真正的用户控件模板。我只需要一个包含 html 的字符串。这就是我想要做的事情:

public class MyUserControl: UserControl
{
public string TitleFormat { get; set; }

private void ShowContent()
{
...
string output = String.Format(TitleFormat, title) + someContent;
ltlOutput.Text = output.
}
}

在标记中:

<UC:MyUserControl id="muc1" runat="server">
<TitleFormat>
<a href="www.somewhere.com"><h3>{0}</h3></a>
</TitleFormat>
</UC:MyUserControl>

我该如何设置?

最佳答案

以下是答案(由 Decker Dong 在 asp.net 论坛中提供):

To nest another class into one, you have to declare a new property but just declare it is an InnerProperty. And set its Design properties. Now here's a full sample for you:

[ParseChildren(true),PersistChildren(false)]
public partial class MyUserControl : System.Web.UI.UserControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public string TitleFormat
{
get;
set;
}

protected void Page_Load(object sender, EventArgs e)
{

}
}

通过这些属性,您可以使用问题中所写的控件。

关于asp.net - 在 asp.net UserControl 上公开嵌套的 HTML 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11210763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com