Freigeben über


ASP.NET Control Registration Simplicity

Scott Guthrie has done it again and talks to us about how to register controls for pages in a web application one time instead of on each page.

Trick- How to Register User Controls and Custom Controls in Web.config

 

Basically, instead of this:

 

<% Register TagPrefix="scott" TagName="header" Src="Controls/Header.ascx" %
<% Register TagPrefix="scott" TagName="footer" Src="Controls/Footer.ascx" %
<%@ Register TagPrefix="ControlVendor" Assembly="ControlVendor" %>

 

Do this in the web.config:

 

<?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>