Forced accept.
Computer101
EE Admin
Main Topics
Browse All TopicsHi,
I have created a primary web application project and several subproject by using ASP.NET. Now I want to define a web user control under the root project and share it with all of subprojects. It seems it doesn't work if the web user control created under the root project. But it works well if it is created under each subproject folder. So the web user control can't be shared between primary project and sub projects?
Thanks a lot,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: CJ_SPosted on 2007-06-07 at 12:12:05ID: 19236464
Your current usercontrol probably consists of two files.
;
1) .ascx
2) .ascx.cs or .ascx.vb
Those two files are your problem.
If you want to share your usercontrol in other projects you should make the usercontrol be only one file, and it must be a .cs file.
Instead of writing declarative code (html and asp:xxx tags) you should create a new Class within a project and have it derive from the System.Web.UI.WebControl class or another existing WebControl.
Within this newly created class you will have to override specific methods, like CreateChildControls (and other methods - depending on your current .ascx user control). These methods should take care of building the actual control.
public class MyNewControl System.Web.UI.WebControl
{
protected override void CreateChildControls()
{
LinkButton lb1 = new LinkButton();
lb1.ID = "mylinkbutton";
lb1.Text = "Click me";
lb1.Click += new EventHandler(lb1_Click);
this.Controls.Add(lb1);
base.CreateChildControls()
}
private void lb1_Click(object sender, EventArgs e){
... take care of click event ..
}
}
When compiled you can add this new WebControl to your subprojects by:
1) referencing the correct library (.dll)
2) implementing it with the correct Register tag on the page you want to use your control
...
<%@ register Tagprefix="uc" TagName="mycontrol" Assembly="yourclass, yourassembly" %>
...
3) use the control
...
<uc:mycontrol runat="server" ... />
...
4) write every other code you need to manage your control
I hope this information was a little helpful.
There however is also another method - using some kind of version control. Most version controls allow you to create stores, and reference another store with needed include files. This 'other' store can then also be updated with the latest version by issueing an update from the 'new' project. This method works almost the same as you currently use - it makes a copy of the existing file and puts it in a new directory. The advantage is that you can always update to the latest version with 1 click - instead of manually copying the file again.
Your call!
Cheers,
CJ.