今天在弄一个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为literal赋值,需要怎么修改呢??如果要在控件中间实现可以添加页面变量<% ="what.."%>呢?
谢谢!
for(int i=0;i<this.contorls.count;i++)
{
if(this.contorls[i].gettype().fullname== "webcontrol")
{
webcontrol wc=(webcontrol)this.contorls[i];
Literal Literal1=(Literal1) wc.Findcontorl("Literal1");
Literal1.text="abc";
}
}