ASP.NET - @Register 指令的放置
过去我总是把我的<%@ 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常这不是一个好的做法,因为一个页面上可能有多个用户控件。我将继续在顶部执行此操作,或者如果它是应用程序范围内的,请考虑将其放入您的 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
请参阅有关指令语法的 MSDN 参考
摘录:
以及 @Register 的有用信息。
See the MSDN reference on Directive Syntax
Excerpt:
And useful info for @Register.