ASP.NET Register User Controls Globally

If you drag a user control onto a web page in design view, Visual Studio automatically adds a Register tag at the top of the page:

<%@ Register src="~/UserControls/RSSReader.ascx" tagname="RSSReader" tagprefix="uc" %>

This is fine if you only have a few controls on a couple of pages. But what if you decide to move the User Controls? You have to patch up every Register tag on each page! There is an easier way; User Controls can be registered globally in the Web.config file:

<system.web>
  <pages>
    <controls>
      <add tagPrefix="uc" src="~/UserControls/RSSReader.ascx" tagName="RSSReader"/>
    </controls>
  </pages>
</system.web>

FYI – This is the same part of Web.config where you can register custom server controls.

Advertisements
This entry was posted in Tips and Tricks and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s