在 Web.config 中是否可以在指定目录中注册所有用户控件控件、用户、目录中、Web

由网友(十字路口)分享简介:目前我在 Web.config 中分别注册每个用户控件Currently I'm registering every user control separately in 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:

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

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

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.

还有更多信息这里和

阅读全文

相关推荐

最新文章