如何在asp.net中将用户控件的引用添加到web.config [英] How do I add reference of user control to web.config in asp.net

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

问题描述

'我想在网站的代码隐藏中以编程方式创建用户控件的实例*。我发现以编程方式引用用户控件的类的唯一方法是:

在web.config中注册控件并将控件放在页面上(工作,但我不想要控制页面,因为我想动态添加它。
添加<%@ 参考 控制 = Name.aspx > aspx page top。

理想情况下 想要 to 任何 aspx page reference control 没有 ha ving to put <%@ 参考> 声明 top < span class =code-attribute> 每个 页。 知道 注册 控件 web.config so 不要 每个 页面, so < span class =code-attribute>我
想知道 如果 类似 存在 for references。 几乎 某些 缺少 某事 about 整个 注册/引用 概念, so 或许 只是 说明 什么 最佳 方式 to do in order。

解决方案

将包含UserControl的DLL添加到Bin文件夹。您可以像使用添加引用一样使用它。


 <?  xml     version   =  1.0  >  

< 配置 >

< system.web >

< pages >
< controls >
< add < span class =code-attribute> tagPrefix = scottgu src = 〜/ Controls / Header.ascx tagName = 标题 / > ;
< add tagPrefix = scottgu src = 〜/ Controls / Footer.ascx tagName = 页脚 / >
< add tagPrefix = ControlVendor assembly = ControlVendorAssembly / >
< / controls < span class =code-keyword>>
< / pages >

< / system.web >

< / configuration >







http://weblogs.asp.net/scottgu/archive/2006/11/26 /tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx [ ^


'm looking to create an instance of a user control programatically in a codebehind of a web site*. The only ways I've found to reference the class of the user control programatically have been:

Register the control in the web.config and drop the control on the page (works, but I don't want the control on the page as I want to dynamically add it).
Add a <%@ Reference Control="Name.aspx"> to the aspx page at the top.

Ideally I would want to have any aspx page reference the control without having to put the <%@ Reference> declaration at the top of each page. I know I can "Register" controls in the web.config so I don't have to do that on every page, so I'm wondering if something similar exists for references. I'm almost certain I'm missing something about the whole registering/referencing concept, so perhaps just an explanation of what the best way to do this is in order.

解决方案

Add the DLL containing your UserControl to the Bin folder. You will be able to use it as if you had added a reference.


<?xml version="1.0"?>

<configuration>

  <system.web>

    <pages>
      <controls>
        <add tagPrefix="scottgu" src="~/Controls/Header.ascx" tagName="header"/>
        <add tagPrefix="scottgu" src="~/Controls/Footer.ascx" tagName="footer"/>
        <add tagPrefix="ControlVendor" assembly="ControlVendorAssembly"/>
      </controls>
    </pages>

  </system.web>

</configuration>




http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx[^]


这篇关于如何在asp.net中将用户控件的引用添加到web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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