Register User Web Controls (ascx) Globally
One of the most impotent OPP principles is encapsulation!. We do encapsulate anything or code that varies. So what about the user interface (aspx pages I mean) are we able to encapsulate some lines that varies between pages?
Actually; YES! But not for everything, here I want to show you a way to encapsulate a user web control (ascx) to be used in any page that you want without registering it every time. This feature came with .net 2.0 and cannot be used with .net 1.1. all you have to do is;
- Create a new web.config file ( if you do not have one on your project)
- Add or use the controls section on the web.config file as below;
Let us say that I have a use control that is tagnamed as “myUserC” so I can use it this way
<sysetm.web>
<pages>
<controls>
<add tagPrefix="MyC" src=”~/siteControls/ myUserC.ascx"
tagName=" myUserC " />
</controls>
</pages>
</sysetm.web>
Here the tag prefix is the tag that will be used on user interface line like this
< myUserC:ARWebViewer ID="usercontol1" runat="server" />
Hope This Helps
Ref:
http://msdn.microsoft.com/en-us/library/ms164640.aspx