DOT NET 4.0 – Directives for Web Forms Pages – @ Register Directives

Associates aliases with namespaces and class names for concise notation in custom server control syntax.

<%@ Register tagprefix=”tagprefix Namespace=”namespace” Assembly=“assembly” %>

<%@ Register tagprefix=”tagprefix” Tagname=”tagname” Src=”pathname” %>

Attributes

tagprefix

An alias to associate with a namespace.

tagname

An alias to associate with a class.

Namespace

The namespace to associate with tagprefix.

Src

The location (relative or absolute) of the declarative user control file to associate with the tagprefix:tagname pair.

Assembly

The assembly in which the namespace you are associating with tagprefix resides.

Note The assembly name does not include a file name extension.

Remarks

Including this directive in a page or user control allows you to layout custom server controls or user controls using declarative custom server control syntax.

Use this directive in one of the following situations.

  • You are declaratively adding a custom ASP.NET server control to a page or user control.
  • You are adding a declarative user control to a page or user control.

For declarative user controls, use the tagname and tagprefix attributes. These are always used together as a colon-separated pair (tagprefix:tagname) when you declare the control in the page.

When including custom server controls that you have compiled into a .dll for use with your application, use the tagprefix with the Assembly and Namespace attributes. If you do not include the Namespace attribute, or if you assign an empty string to it, a parser error will occur.

Important When you develop a custom server control, you must include it in a namespace. If you do not, it will not be accessible from an ASP.NET page. For more information about developing custom ASP.NET server controls, see Developing a Simple ASP.NET Server Control.

Example

The following code fragment uses <%@ Register %> directives to declare tagprefix and tagname aliases for a server control and a user control. The first directive declares the MyTag alias as a tag prefix for all controls residing in the MyCompany:MyNameSpace namespace. The second directive declares Acme:AdRotator as a tagprefix:tagname pair for the user control in the file Adrotator.ascx. The aliases are then used in custom server-control syntax within the form to insert an instance of each server control.

<%@ Register Tagprefix=”MyTag” Namespace=”MyCompany:MyNameSpace” Assembly=”MyAssembly” %>

<%@ Register Tagprefix=”Acme” Tagname=”AdRotator” Src=”AdRotator.ascx” %>

<HTML>

<body>

<form runat=”server”>

<MyTag:MyControl id=”Control1″ runat=”server” /><BR>

<Acme:AdRotator file=”myads.xml” runat=”server” />

</form>

</body>

</HTML>

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s