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

Use user control in the same folder as the page(在与页面相同的文件夹中使用用户控件)
本文介绍了在与页面相同的文件夹中使用用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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.

这篇关于在与页面相同的文件夹中使用用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)