Thursday, September 27, 2012

ASP.NET - Registering an user control in web.config

Instead of registering an user control (.ascx) on top of every page we need it, there's a way to register it on the web.config file one time only.
For example, here I am registering an user control of a contact form:

    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
        <add tagPrefix="uc" tagName="contact_form" src="~/uc/contact_form.ascx"/>

And then I can use it anywhere on my website:

<div style="width: 1000px; min-height: 510px;">
<uc:contact_form ID="my_contact_form" runat="server" />


No comments:

Post a Comment