zoukankan      html  css  js  c++  java
  • ASP.NET用户控件也可以在Web.Config中进行引用

    我们在引用用户控件时,如果引用控件的文件很多,那么经常要每个页面都加上Register 指令,真是痛苦。

    还好,我们可以在web.config里注册控件:

    <configuration>
      <system.web>
        <pages>
           <controls>
             <add tagPrefix="MyControl" src="~/Controls/WebUserControl.ascx" tagName="MyButton"/>
           </controls>
        </pages>
      </system.web>
    </configuration>
    同样的,第三方控件也可以在这里注册

    <configuration>
      <system.web>
        <pages>
           <controls>
             <add tagPrefix="ControlVendor" assembly="ControlVendorAssembly"/>
           </controls>
        </pages>
      </system.web>
    </configuration>
    需要注意的是,上面用户控件中“~”句法的使用。对那些不熟悉这个符号的人,ASP.NET中“~”符号意思是“从应用的根路径来定位”,它提供了一个很好的方法来避免在你的编码里到处使用“..”。在web.config文件里声明用户控件时,你总是应该使用它,因为页面也许会使用在不同子目录里的控件,所以你应该总是始终如一地从应用的根路径开始定位这些控件。


    一旦你在web.config 文件中声明好这些控件后,你就可以在你网站上的任何一个页面,母板页或者用户控件中使用它们了,象这样(不再需要注册指令):

    <html>
    <body>
        <form id="form1" runat="server">
            <MyControl:MyButtonIDMyControl:MyButtonID="MyButton1" runat="server" /> 
        </form>
    </body>
    </html>

  • 相关阅读:
    PHP数组(数组正则表达式、数组、预定义数组)
    面向对象。OOP三大特征:封装,继承,多态。 这个讲的是【封存】
    uvalive 3938 "Ray, Pass me the dishes!" 线段树 区间合并
    LA4329 Ping pong 树状数组
    HDU 1257 最少拦截系统
    HDU 1260 Tickets
    codeforce 621D
    codeforce 621C Wet Shark and Flowers
    codeforce 621B Wet Shark and Bishops
    codeforce 621A Wet Shark and Odd and Even
  • 原文地址:https://www.cnblogs.com/wangpei/p/1738262.html
Copyright © 2011-2022 走看看