'm looking to create an instance of a user control programatically in a codebehind of a web site*. The only ways I've found to reference the class of the user control programatically have been: Register the control in the web.config and drop the control on the page (works, but I don't want the control on the page as I want to dynamically add it). Add a <%@ Reference Control="Name.aspx"> to the aspx page at the top. Ideally I would want to have any aspx page reference the control without having to put the <%@ Reference> declaration at the top of each page. I know I can "Register" controls in the web.config so I don't have to do that on every page, so I'm wondering if something similar exists for references. I'm almost certain I'm missing something about the whole registering/referencing concept, so perhaps just an explanation of what the best way to do this is in order.
<?xml version="1.0"?> <configuration> <system.web> <pages> <controls> <add tagPrefix="scottgu" src="~/Controls/Header.ascx" tagName="header"/> <add tagPrefix="scottgu" src="~/Controls/Footer.ascx" tagName="footer"/> <add tagPrefix="ControlVendor" assembly="ControlVendorAssembly"/> </controls> </pages> </system.web> </configuration>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)