ASP.NET Web Forms: Use same tagPrefix for web controls from different namespaces

Viewed 933

I've registered two namespaces in Web.config like this:

<add tagPrefix="a" assembly="WebApplication1" namespace="WebFormsApplication1.Controls1" />
<add tagPrefix="a" assembly="WebApplication1" namespace="WebFormsApplication1.Controls2" />

I'm using them like this in an .aspx page:

<a:WebCustomControl1 ID="Control1" runat="server"></a:WebCustomControl1>
<a:WebCustomControl2 ID="Control2" runat="server"></a:WebCustomControl2>

Here's the (broken) .designer.cs file VS generates for that page (notice that it uses Controls2 namespace for both controls, although Control1 lays in Controls1 namespace):

protected global::WebFormsApplication1.Controls2.WebCustomControl1 Control1;
protected global::WebFormsApplication1.Controls2.WebCustomControl2 Control2;

It looks like the second <add in Web.config is overwriting the first one. I want it to append rather than overwrite, is it possible?


I guess there are other alternatives as well:

  1. Put everything in a single namespace
  2. Use an unique tagPrefix for each namespace

But they are not cool since we have about a hujilion of controls here.

Notice that if register the namespaces in aspx itself, it'll work fine:

<%@ Register TagPrefix="a" Namespace="WebFormsApplication1.Controls2" Assembly="WebFormsApplication1" %>
<%@ Register TagPrefix="a" Namespace="WebFormsApplication1.Controls" Assembly="WebFormsApplication1" %>

So it looks like some bug in Web.config parsing.

(I'm on VS 2017, but they told me it happened since VS 2010 at least).

1 Answers
Related