ASP.NET Web Forms: Use the same tag tags for web controls from different namespaces

I registered two namespaces in the Web.config

following way:

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

      

I use them like on the page .aspx

:

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

      

Here's a (split) .designer.cs

VS file generated for this page (note that it uses the namespace Controls2

for both controls, even though it's Control1

in the namespace Controls1

):

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

      

It looks like the second one <add

in the Web.config is overwriting the first one. I want it to be added and not overwritten, is this possible?


I think there are other alternatives:

  • Put everything in one namespace
  • Use unique tagPrefix

    for each namespace

But they are not cool as we have about the hujilion of management here.

Note that if you register namespaces in aspx

, it will work fine:

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

      

So it looks like a parsing error Web.config

.

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

+3


source to share


1 answer


Where I've needed this in the past, I've removed the designer files and manually declared all the controls in the code.



There might also be a way (but I don't remember exactly how) to tell the Designer not to create these specific controls in the designer file. Then you manually add them to the code behind.

+1


source







All Articles