Register your user controls and custom controls in Web.Config

In ASP.NET web application you can develop user controls and custom server controls to increase your productivity and decrease code repetition. To use these user controls at your web pages you can register like this:

<%@ Register Src="Controls/somecontrol.ascx" TagName="SomeControl" TagPrefix="myPrefix" %>

And use like this:

<html>
<body>
    
<form id="form1" runat="server">
        
<myPrefix:header ID="SomeControl1" runat="server" />
    </
form>
</body>
</html>

The registration step can be a bit pain if you have too much pages. Also its hard to change the name of the .ascx file name if you registered the control at too much pages.

To avoid these you can try to register your controls at your web.config file in more managable way.

<?xml version="1.0"?>
<configuration>
 
<system.web>
   
<pages>
      
<controls>
        
<add tagPrefix="myPrefix" src="~/Controls/somecontrol.ascx" tagName="S
omeControl"/>
        <
add tagPrefix="
myPrefix" src="~/Controls/othercontrol.ascx" tagName="OtherControl"/>
        <
add tagPrefix="CustomControl" assembly="CustomControlAssembly"/>
      </
controls>
    
</pages>
 
</system.web>
</configuration> 

So you can still use your controls in the same way but you can manage them at one location.
And you can easily copy controls from one page to the other.

Posts created 141

Leave a Reply

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top