ASP.NET - @Register 指令的放置

发布于 2024-08-15 03:39:16 字数 413 浏览 2 评论 0原文

过去我总是把我的<%@ Register ... %>指令位于我的 .aspx 页面顶部,位于 @ Page 指令下方。我最近发现我可以将此寄存器指令放置在 .aspx 页面中的任何位置,并且仍然可以正常运行。我们想知道将这些控件放置在用户控件的第一个实例之上是否会出现任何问题,例如:

<%@ Page .. %>

<div>
<asp:TextBox ..>
...
...
<%@ Register src="~/UserControls/UserControl.ascx" ..>
<uc1:UserControl ..>
...
</div>

如果我们这样做,则可以更轻松地将用户控件从一个页面复制并粘贴到另一个页面上。其他。这种风格有什么缺点吗?

In the past I have always placed my <%@ Register ... %> directive(s) at the top of my .aspx pages just below the @ Page directive. I recently found out that I can place this register directive ANYWHERE in the .aspx page and still have it function correctly. We are wondering if there is any problem people can foresee with placing these right above the first instance of a user control, for example:

<%@ Page .. %>

<div>
<asp:TextBox ..>
...
...
<%@ Register src="~/UserControls/UserControl.ascx" ..>
<uc1:UserControl ..>
...
</div>

If we do it this way, it makes it a lot easier to copy and paste user controls from one page to another. Are there any disadvantages to this style?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抹茶夏天i‖ 2024-08-22 03:39:16

通常这不是一个好的做法,因为一个页面上可能有多个用户控件。我将继续在顶部执行此操作,或者如果它是应用程序范围内的,请考虑将其放入您的 web.config 文件中:

http://weblogs.asp.net/scottgu/archive/ 2006/11/26/tip-trick-如何注册用户控件和自定义控件-in-web-config.aspx

Typically this is not good practice since you could have multiple UserControls on a page. I would continue to do it at the top or if it is application-wide consider placing it in your web.config file:

http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx

香橙ぽ 2024-08-22 03:39:16

请参阅有关指令语法的 MSDN 参考

摘录:

使用时,可以定位指令
.aspx 或 .ascx 文件中的任何位置,
尽管标准做法是包括
它们位于文件的开头。
每个指令可以包含一个或多个
属性(与值配对)
特定于该指令。

以及 @Register 的有用信息。

See the MSDN reference on Directive Syntax

Excerpt:

When used, directives can be located
anywhere in an .aspx or .ascx file,
though standard practice is to include
them at the beginning of the file.
Each directive can contain one or more
attributes (paired with values) that
are specific to that directive.

And useful info for @Register.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文