在 Web.config 中是否可以在指定目录中注册所有用户控件 [英] In Web.config Is it possible to register all user controls in specified directory

查看:18
本文介绍了在 Web.config 中是否可以在指定目录中注册所有用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在 Web.config 中分别注册每个用户控件

Currently I'm registering every user control separately in Web.config

<pages validateRequest="false">
  <controls>
    <add tagPrefix="cc1" src="~/Controls/MyUserControl1.ascx" tagName="MyUserControl1"/>
    ...    
    <add tagPrefix="cc1" src="~/Controls/MyUserControlN.ascx" tagName="MyUserControlN"/>
  </controls>
</pages>

但有时我会忘记签入 web.config.实际上,我通常忘记它已更改跳过它,因为它经常破坏其他设置为连接到本地数据库副本的设置.

But from time to time I forget to checkin web.config. Actually, I usually forget that it have changed skip it because it often breaks settings others set to connect to their local db DB copy.

我想知道是否可以只指定整个 Controls 目录并自动注册那里的所有控件

I was wondering is it possible to just specify whole Controls directory and get all controls there registered automatically

推荐答案

是与否.

基本上,您可以在 web.config 中注册所有用户控件.但是,如果您想在其他用户控件中使用任何用户控件,则会遇到问题.

Basically, you can register all your usercontrols in the web.config. BUT you'll run into problems if you want to use any of your usercontrols within other usercontrols.

所以,如果您永远不会嵌套用户控件,那么您就可以开始了.但是如果你想灵活地嵌套用户控件,你有几个选择:

So, if you're never going to nest usercontrols, you're good to go. BUT if you want the flexibility to nest usercontrols you've got a few options:

  1. 将它们全部注册到 web.config 中,然后,在嵌套的情况下,将要嵌套的控件直接注册到父用户控件中.
  2. 正如 Bryan 上面提到的,将您的用户控件编译成一个程序集,并在 web.config 中引用它们.
  3. 这是最糟糕的选择,但基本上你可以通过将控件放置在子文件夹中来解决在 web.config 中注册所有用户控件时的嵌套问题……这不是一个好选择.
  4. 另一种选择是强类型化您的用户控件,可能为您的用户控件创建基类.

基本上这不是框架中的错误,而是将所有内容编译到单个程序集中的结果.该应用程序本质上无法区分用户控件.

Basically it's not a bug in the framework but a result of compiling everything into a single assembly. The app essentially can't distinguish between user controls.

还有更多信息这里在这里.查看对此的评论

这篇关于在 Web.config 中是否可以在指定目录中注册所有用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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