复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Ascxcontrol.Controls
{
public partial class controlone : System.Web.UI.UserControl
{
//Literal1.Text = RenderUserControlToString("../Controls/controltwo.ascx");
private string RenderUserControlToString(string ucpath)
{
UserControl uc = (UserControl)this.LoadControl(ucpath);
using (TextWriter tw = new StringWriter())
using (HtmlTextWriter htw=new HtmlTextWriter(tw))
{
uc.RenderControl(htw);
return tw.ToString();
}
}
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
controltwo ct = (controltwo)this.LoadControl("../Controls/controltwo.ascx");
ct.Text = i.ToString();
PlaceHolder1.Controls.Add(ct);
}
}
}
}
复制代码
 posted on 2015-06-05 10:34  纳米程序员  阅读(352)  评论(0编辑  收藏  举报