Registering User Controls in the Web Configuration File ASP.Net

Rather than use the registering a User control in each page in which you need to use it by using the <%@ Register %> directive, you can register a User control once for an entire application. You can register a User control in an application’s web configuration file.

Web.Config

<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="ASPXIMAGE" tagName="WebImage" src="~/UserControls/CtrlImage.ascx"/>
</controls>
</pages>
</system.web>
</configuration>

After you register a User control in the web configuration file, you can simply declare the User control in any page, but it does not include the <%@ Register %> directive.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show Application Register</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ASPXIMAGE:WebImage ID="WebImage1" Runat="Server" />
</div>
</form>
</body>
</html>
Tags: ,
Hot on Web:


About author