Site menu:

Links:

RSS .NET RSS

RSS Engadget

Site search

Categories

September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  

Tags

Blogroll

Reference to user control in web.config

I’ve seen that most of people put their user control declaration in individual aspx page, and they declare it on the top of that page. What will happen if you are going to use it on multiple number of pages and i believe most of you would like to have a kind of tag that you can simply use on your web page to add your user control. In here, we declare all the user controls in web.config which I believe is more clean and manageable.

Web.Config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<pages validateRequest ="false">
      <controls>
        <add namespace="System.Web.UI" tagPrefix="asp" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
		<add tagPrefix="MyControl" src="~/MyInternet/usercontrols/paymentgateway.ascx"			tagName="PaymentGateway" />
	  </controls>
    </pages>
	  <httpModules>
		  <add name="WebPageSecurity" type="Ventaur.Web.Security.SecureWebPageModule, WebPageSecurity" />
		  <add name="RadUploadModule" type="Telerik.WebControls.RadUploadHttpModule, RadUpload.Net2" />
		  <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
		  <add name="WebClientAuthorizationModule" type="Microsoft.Practices.CompositeWeb.Authorization.WebClientAuthorizationModule, Microsoft.Practices.CompositeWeb" />
		  <add name="ExceptionLoggerHttpModule" type="Microsoft.Practices.CompositeWeb.EnterpriseLibrary.ExceptionLogger, Microsoft.Practices.CompositeWeb.EnterpriseLibrary" />
		  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </httpModules>

How to use it in ASPX Page

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Checkout-Confirm.aspx.vb"
    Inherits="PaymentTest_Checkout_Confirm" %>
 
<!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">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <MyControl:PaymentGateway ID ="ucpaymentgateway" runat="server" />
    </form>
</body>
</html>

Write a comment