Control c = LoadControl("controls/newss.ascx");//用户控件路径
c2.Controls.Add( new LiteralControl("<div class=\"portlet\" id=\"bs11\">")); //包围在用户控件外围的层,c2为服务器控件
c2.Controls.Add(c); //将用户控件添加进c2
c2.Controls.Add(new LiteralControl("</div>")); //div结束
前台:
<div id="c2" runat="server">
</div>
运行后为:
<div id="c2" runat="server">
<div id="bs11" class="portlet" >
//用户控件newss.ascx的内容
</div>
</div>