Sharing a User Control across Web Applications
page 5 of 8
by Thomas Z.
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 35138/ 87

Rise of the Controls

Now that we have the full setup lets test our controls using the default "webform1.aspx" page.

In order to use any usercontrol we must first add the register directive in the html part of our page.

<%@ Register TagPrefix="DNG" TagName="DateBox" Src="~/Controls/DateBox.ascx" %>

And here is the trick, watch carefully the SRC. We are tricking the asp.net engine by using an App-Based path with the ~ prefix instead of a classic virtual path. If we had used a virtual path asp.net would have thrown the following error "maps to another application, which is not allowed". Using and App-Based path asp.net doesn't notice that the file comes from a different application and we can use our ascx files, great !

Lets move on and add our user controls to our page and compile the project.

<DNG:DateBox id="DateBox1" Company="DNG" Year="1984" runat="server" />

If we did everything correctly our shared user control should appear on our test page.



Looks nice ;)


View Entire Article

User Comments

Title: require same solution for .net 2.0   
Name: Mital
Date: 2007-10-24 8:09:33 AM
Comment:
To Graham,

as you said u have published a newer verion for .net 2, but that link is not working and I want it urgently Please help me.
Thanks in advance
Title: That's Great, Really.   
Name: Shahzad
Date: 2006-12-14 11:45:22 AM
Comment:
Thanks very much buddy. Actually, i was looking for a solution to manipulate a control all dynamically, and after a lot of search i found this article, it helped me a lot.
Thanks and keep it up!
Title: A newer solution to the problem   
Name: Graham
Date: 2006-07-26 7:45:17 AM
Comment:
I've just posted a new solution for .Net 2 that allows you to include UserControls, Pages and MasterPages in a single Web Application Project library that can be distributed easily.

Its quick and easy to set up, there a description of how it works and a solution download that demonstrates everything working at,
http://www.nearasmakesnomatter.co.uk/wapul.htm
Title: Thanks   
Name: MG
Date: 2006-02-08 1:32:39 PM
Comment:
The ~ trick is great. I was struggling with virtual directories. Thanks for the help.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-10-15 6:18:36 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search