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

查看:117
本文介绍了在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中。其实,我经常忘记它已经改变跳过它,因为它常常打破别人的设置设置连接到他们的本地数据库DB副本。

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.

我想知道是否有可能只指定整个控制目录,并得到所有的控件有自动注册

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. 正如布赖恩如上所述,编译你的用户控件到一个程序,并在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.

有的一些信息这里和<一个href=\"http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx#1056687\"相对=nofollow>在这里。检查出这个的评论

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

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