c# - ASP.NET Web 窗体 : Use same tagPrefix for web controls from different namespaces

标签 c# asp.net visual-studio webforms

我已经 registered two namespacesWeb.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 中覆盖第一个。 我希望它附加而不是覆盖,这可能吗?


我想还有其他选择:

  1. 将所有内容放在一个命名空间中
  2. 使用唯一的 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/

相关文章:

visual-studio - 将 nuget 包中的内容文件设置为 "copy local : always"

c# - WPF:使网格适应图像

git 无法解决 rebase 冲突,因为 mergetool 没有 pop

c# - 如何优化许多相同的图像?

c# - Android RatingBar的MvvmCross实现

c# - SQLServerCE 无法在 select 语句中使用 rtrim - SQLCEException

c# - ASP .NET 无法解析类型的服务

c# - 如何在 ASP.NET Web API 应用程序中调用另一种异步方法

c# - 在二进制文件中间插入字节

javascript - $ ("123").ready (fn(){}) 无论如何都会触发