How to Add the Reference of a User Control in the webconfig file in ASPNET

At the time of working, developers register the User Controls to individual asp.net pages where, controls are in use. If the control is in use in most of the pages of the site, the reference can be added at one place only, that is in the web.config.

Code to add in web.config file to register the user control
<configuration>
  <system.web>
    <pages>
      <controls>
        <add tagPrefix="uc1" src="~/usercontrols/Address1.ascx" tagName="Address1"/>
        <add tagPrefix="uc2" src="~/usercontrols/Address2.ascx" tagName="Address2"/>
      </controls>
    </pages>
  </system.web>
</configuration>

Code to use the user control in the page
Open your aspx page and place the below code.

<uc1:Address1 ID="ucAddress1" runat="server"/>
<uc2:Address2 ID="ucAddress2" runat="server"/>

Comments