2017-06-29 41 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在設計器文件中不生成這些特定控件。然後你在後面的代碼中手動添加它們。

相關問題