我想自定义一个可以像这样使用的webcontrol:
<cc1:TitleEx runat="server" Theme="Sky" DemoUrl="what.swf" Left="150" Width="250">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</cc1:TitleEx>
基类是:
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
if (this.HasControls())
{
this.Controls.Clear();
}
ViewState["Text"] = value;
}
}
/// <summary>
/// child control's content
/// </summary>
protected StringBuilder HtmlContent = new StringBuilder();
protected override void AddParsedSubObject(object obj)
{
if (obj is LiteralControl)
{
HtmlContent.Append(((LiteralControl)obj).Text);
this.Text = HtmlContent.ToString();
}
else
{
if (obj != null)
{
HtmlContent.Append(GetControlHtml(obj as Control));
this.Text = HtmlContent.ToString();
}
}
}
/// <summary>
/// get the child controls' html
/// </summary>
protected string GetControlHtml(Control ctl)
{
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(tw);
ctl.RenderControl(writer);
sb.Append(writer.InnerWriter.ToString());
return sb.ToString();
}
我的问题是当我在Page_Load()
中将字符串设置为此文字控件时,但字符串无法显示。我也尝试在OnPreInit()
,OnPreLoad()
中设置值,但仍然没有运气。
以前有人遇到过这个问题吗?
你如何解决这个问题?
答案 0 :(得分:0)
我通过反映小组找到了答案。 这是我的解决方案.http://www.cnblogs.com/coolkiss/archive/2010/12/30/1921494.html