Home > Interview Questions > ASP.NET > What is @Register directive in asp.net?

What is @Register directive in asp.net?

by Thamil   on 03/10/2015   Category: ASP.NET   |  Level: Intermediate   |  Views: 871    |  Points: 25     |  Gold 

The register control is used in asp.net for registering the user controls and custom controls in the web pages. @Register associates the control with a specific TagPrefix and allows you to use it in your aspx markup. Shortly @Register directives informs to the .net compiler saying that custom controls are added in the page. Suppose I have a header and footer user controls which I need to use my all web pages, so simply drag the user control into page and it will create the tagename and tagprefix as shown below and maintain the tagprefix name same so that we can maintain our user controls easily.

<%@ Register tagprefix="tagprefix" tagname="tagname" src="pathname" %>

Sample code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="regiser.aspx.cs" Inherits="IQsamples.regiser" %>
<%@Register TagPrefix="SampleTag" Tagname="Header" Src="~/controls/header.ascx"%>
<%@Register TagPrefix="SampleTag" Tagname="Footer" Src="~/controls/footer.ascx"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<form id="form1" runat="server">
<SampleTag:Header id="DNGHeader" runat="server"/>
<SampleTag:Header id="DNGFooter" runat="server"/>

« How do you handle exceptions in asp.net application?
» List of validation controls in asp.net?
Post Question  |  Question Home

Recent Posts

User Responses

No response found, be the first to review this question.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts

1 ??????? ?? ????? New! Forum