2017-06-29 40 views
3

Web.config已经registered two namespaces这样的:ASP.NET Web窗体:用于Web控件使用相同的TagPrefix从不同的命名空间

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

我在.aspx页面使用它们像这样:

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

这里的(碎).designer.cs文件VS生成该页面(请注意,它使用Controls2命名空间这两个控件,虽然Control1奠定了在Controls1命名空间):

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

它看起来像Web.config中的第二个<add覆盖第一个。 我想要它追加而不是覆盖,这有可能吗?


我想有其他选择还有:

  1. 把一切都放在一个单一命名空间
  2. 使用独特tagPrefix每个命名空间

但他们不冷静,因为我们在这里有一个关于控制的hujilion。

注意,如果注册的命名空间中aspx本身,它会很好地工作:

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

所以它看起来像在Web.config解析了一些bug。

(我在VS 2017上,但他们告诉我这是自VS 2010以来发生的事情)。

回答

1

在过去需要这种情况的情况下,我删除了设计器文件并手动声明后面代码中的所有控件。

也可能有一种方法(但我不记得具体如何)告诉Designer在设计器文件中不生成这些特定控件。然后你在后面的代码中手动添加它们。

相关问题