.

Friday, June 20, 2008

What is the @Register Directive?

What is the @Register directive used for? What is the purpose of @Register directive in ASP.NET?

Directives in ASP.NET are used to set attributes for a page. The @Register directive is a directive used to register user defined controls on a web page. A user created server control has an ascx extenstion. These controls inherit from the namespace System.Web.UI.UserControl. This namespace inherits from the System.Web.UI.Control.

A user control may be embedded in an aspx web page using the @Register directive. A user control cannot be executed on its own independently, but may be registered on a web page and then used out there. Below is the syntax for registering an @register directive in an aspx page in ASP.NET

<%@ Register TagPrefix="UC1" TagName="UserControl1" Src="UserControl1.ascx" %>

The TagPrefix attributes is used to specify a unique namespace for the user control. The TagName is a name used to refer a user control uniquely by its name. Say we want to use this control in a webpage, we may use the code below...

No comments:

.