在与页面相同的文件夹中使用用户控件在与、控件、页面、文件

2023-09-08 09:32:32 作者:behalf[利益]

我在 ASP.NET 2 页面运行时收到此消息:

I get this message at runtime of ASP.NET 2 page :

页面MyFolder/blabla.aspx"不能使用用户控件MyFolder/MyControl.ascx",因为它在web.config中注册并与页面位于同一目录中.

The page 'MyFolder/blabla.aspx' cannot use the user control 'MyFolder/MyControl.ascx', because it is registered in web.config and lives in the same directory as the page.

当然,我可以将它们分成 2 个不同的文件夹,从而解决问题,但问题是:

Of course I can separate them to 2 different folders and thus solve the problem, but the question is :

WTF !?!?!为什么我不能将它们放在同一个文件夹中?!为什么他们都不能..相处!?!:)

WTF !?!?! Why I can't put them in the same folder ?! Why can't they all .. get along !?! :)

谢谢

推荐答案

由于内部设计考虑,此限制是设计使然:性能.

This limitation is by design due to an internal design consideration re: performance.

请参阅此处了解更多信息.

备注

TagPrefixInfo 类允许您以编程方式访问和修改存储在配置文件中的标签前缀信息.它提供与 ASP.NET @Register 相同的功能指示.标记前缀将 ASP.NET 中的命名空间"与自定义控件必须包含的程序集和命名空间和用户控件正常工作.存储 TagPrefixInfo 对象作为 TagPrefixCollection 对象的成员.这TagPrefixCollection 类允许您以编程方式访问并修改 pages 部分的 controls 子部分配置文件.

The TagPrefixInfo class allows you to programmatically access and modify tag-prefix information stored in a configuration file. It provides the same functionality as the ASP.NET @Register directive. Tag prefixes associate a "namespace" in ASP.NET to the assemblies and namespaces that must be included for custom controls and user controls to work properly. TagPrefixInfo objects are stored as members of a TagPrefixCollection object. The TagPrefixCollection class allows you to programmatically access and modify the controls subsection of the pages section of a configuration file.

TagPrefixInfo 对象使用 add 添加到集合中元素并为 tagPrefix 属性指定一个值其他相关属性的值.另一个需要信息因您将使用的控件类型而异指定标签前缀:

TagPrefixInfo objects are added to the collection using the add element and specifying a value for the tagPrefix attribute along with values for other relevant attributes. The other required information varies based on the kind of control you will use with the specified tag prefix:

如果是用户控件,则必须定义 标签前缀, 标签名 和 Source 属性.如果是自定义控件,则必须定义 标签前缀, 命名空间 和 Assembly 属性.程序集如果控件在应用程序代码中,则不需要属性目录.相同的 tagPrefix 值可用于映射到多个程序集或命名空间. If it is a user control, you must define the TagPrefix, TagName, and Source properties. If it is a custom control, you must define the TagPrefix, Namespace, and Assembly properties. The Assembly property is not required if the control is in the application code directory. The same tagPrefix value can be used to map to multiple assemblies or namespaces.

注意 指定源时,用户控件本身不得与页面位于同一目录中.如果是,您将获得运行时尝试加载页面时出错.

Note When a source is specified, the user control itself must not be in the same directory as the page. If it is, you get a run-time error when you attempt to load the page.