编程方式加载用户控件与web.config中引用 [英] Programmatically load UserControl with reference in web.config

查看:234
本文介绍了编程方式加载用户控件与web.config中引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Web.config中注册为用户控件下方。
我如何动态地标记名头从code-背后加载用户控件到占位符?
我使用ASP.NET 4.0

 <结构>
  <&的System.Web GT;
    <网页和GT;
      <控制与GT;
        <添加标签preFIX =blogUcSRC =〜/控制/头/ Header.ascx变量名=标头/>
      < /控制>
    < /页>
  < /system.web>
< /结构>


解决方案

调用 TemplateControl.ParseControl 方法:

 控制控制= TemplateControl.ParseControl(< blogUc:头RUNAT =服务器/>中);
this.placeHolder.Controls.Add(对照组);

I register usercontrols in Web.config as below. How do i dynamically load usercontrol with tagname header from code-behind into a placeholder? I Use ASP.NET 4.0

<configuration>
  <system.web>
    <pages>
      <controls>
        <add tagPrefix="blogUc" src="~/Controls/Header/Header.ascx" tagName="header"/>
      </controls>
    </pages>
  </system.web>
</configuration>

解决方案

Call the TemplateControl.ParseControl method:

Control control = TemplateControl.ParseControl("<blogUc:header runat='server' />");
this.placeHolder.Controls.Add(control);

这篇关于编程方式加载用户控件与web.config中引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆