我已经 registered two namespaces在 Web.config
像这样:
<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;
看起来像第二个<add
在 Web.config 中覆盖第一个。
我希望它附加而不是覆盖,这可能吗?
我想还有其他选择:
- 将所有内容放在一个命名空间中
- 使用唯一的
tagPrefix
对于每个命名空间
但它们并不酷,因为我们这里有大约 hujilion 控件。
请注意,如果在 aspx
中注册 namespace 本身,它会工作正常:
<%@ Register TagPrefix="a" Namespace="WebFormsApplication1.Controls2" Assembly="WebFormsApplication1" %>
<%@ Register TagPrefix="a" Namespace="WebFormsApplication1.Controls" Assembly="WebFormsApplication1" %>
所以它看起来像 Web.config
中的一些错误解析。
(我在 VS 2017 上,但他们告诉我它至少从 VS 2010 开始就发生了)。
最佳答案
在过去我需要这个的情况下,我删除了设计器文件并在后面的代码中手动声明了所有控件。
可能还有一种方法(但我不记得具体是怎么做的)告诉设计器不要在设计器文件中生成那些特定的控件。然后你在后面的代码中手动添加它们。
关于c# - ASP.NET Web 窗体 : Use same tagPrefix for web controls from different namespaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44825626/