Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET @Register vs. @Reference

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

like image 460
contactmatt Avatar asked Jan 30 '11 03:01

contactmatt


People also ask

What is the need of @register directive in user control?

@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.

Which directive is used in user control?

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.

How ASP.NET should process the page?

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.


1 Answers

@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 %> 
like image 153
Mark Cidade Avatar answered Oct 10 '22 02:10

Mark Cidade