In Tip#8 we saw how to create a Web User control, register a Web User Control and use the Web User control in your page. Note that VS added a @Register directive right at the top of the page on drag drop of the user control on to your page.

But in future if you want to move the location of your User controls you will be forced to change the Register directive in multiple places depending on how many pages you have used the User Control. This could be a pain. This can be easily solved by moving the registration of the user control to your Web.config file with the following entry, so that any change in location can be updated only at one place.

Web config entry would look like:
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="MyControl" src="~/Controls/WebUserControl.ascx"
tagName="MyButton"/>
</controls>
</pages>
</system.web>
</configuration>

Once the web config entry is made. The control can then be used in any page like this:

<body>
    <form id="form1" runat="server">
        <MyControl:MyButton ID="MyUserControl" runat="server" />
    </form>
</body>

 

Reshmi Mangalore

SDET, Web Development Tools