Is it possible to register a complete namespace of usercontrols in an aspx-File, instead of each control seperately?
I have created a bunch of usercontrols and collected them into an own namespace “MyWebControls”, like this:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LevelFilter.ascx.cs" Inherits="MyWebControls.LevelFilter" %>
Codebehind:
namespace MyWebControls
{
public partial class LevelFilter : System.Web.UI.UserControl
{
...
}
}
What I tried now to include them in my pages (and what did not work):
<%@ Register Namespace="MyWebControls" TagPrefix="ucs" %>
...
<ucs:LevelFilter />
Is there any way to do this? Apparently it works with external assemblies like AjaxControlToolkit, so I guess this should be possible.
I am using ASP.NET 4.0.
With user controls there’s just no way to do this 🙁 You can only use the
namespaceandassemblyattributes to bring in controls from an assembly, and usercontrols don’t export to a separate assembly very well (I suspect it’s to do with the way user controls have separate code and markup).If you really have your heart set on this you’ll need to convert your user controls to server controls – there’s a piece on the CodeProject here that looks like it might offer some shortcuts to doing this.
Otherwise my best suggestion is to register all your user controls centrally in your web.config so they are available to all your pages. To do this, in your web.config under
system.web/pages/controlsadd each of them like this: