ASP.NET @Register vs. @Reference

前端 未结 2 920
忘掉有多难
忘掉有多难 2021-02-05 02:54

I\'m working with referencing user controls on my ASPX page and I\'m wondering what the difference is between these two page directives.

@Reference @Register

2条回答
  •  孤城傲影
    2021-02-05 03:11

    @Register is the more commonly used directive. You use this when you want to use a user control in your aspx or ascx page declaratively. @Register associates the control with a specific prefix and you can then use it in your markup.

    @Reference only tells ASP.NET to compile the other control when your aspx or ascx page is compiled. That makes sure it is available at run-time and can be added to your control hierarchy programmatically. This is less common since dynamically changing user controls at runtime is not comon.

    Here's a good blog post about it.

    http://weblogs.asp.net/johnkatsiotis/archive/2008/08/13/the-reference-directive.aspx

提交回复
热议问题