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
@register directive will be used, when you drag a user control onto your page. This directive registers your user control on the page so that the control can be accessed by the page. @Register directive informs the compiler that a user control added to the page.
The @Assembly Directive attaches assemblies to the page or an ASP.NET user control thereby all the assembly classes and interfaces are available to the class. This directive supports the two attributes Name and src. The Name attribute defines the assembly name and the src attribute defines the source of the assembly.
ASP.NET pages usually contain directives that allow you to specify page properties and configuration information for the page. The directives are used by ASP.NET as instructions for how to process the page, but they are not rendered as part of the markup that is sent to the browser.
@Register
is primarily used for registering tag prefixes to declaratively use controls within a page.
<%@ Register tagprefix="my" namespace="MyNamespace" %> <my:CustomControl runat=server />
@Reference
is primarily used to refer to a page or user control (by file name or virtual path) to programatically refer to members of the page or control.
<%@ Reference Control="MyControl.ascx" %> <% MyControl ctrl = (MyControl) Page.LoadControl("MyControl.ascx"); ctrl.CustomProperty = "..."; //REFERENCE directive is needed to access property %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With