首页 新闻 会员 周边 捐助

webcontrol 包含另一个webcontrol

1
悬赏园豆:15 [待解决问题]

今天在弄一个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.."%>呢?

谢谢!

Chris Cheung的主页 Chris Cheung | 初学一级 | 园豆:155
提问于:2010-12-29 13:31
< >
分享
所有回答(1)
0

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

 

}

}

keepsilence | 园豆:457 (菜鸟二级) | 2011-01-24 16:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册