Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I currently have an existing web application. Now we want to create some sister sites which will allow us to utilize some of our existing classes and controls from our main site. I have one of the sister sites project built and added a reference to the DLL of our main site so to have access to our "common" classes. This part is working just fine. However, we have some ASCX controls that we would also like to use in the sister web application that is from our main web application. Does anyone know how to accomplish this?

Thanks In Advance,

Brad
Posted

You can't share User Controls in that manner. They would need to be copied to each project. If you need to reuse the controls then create as a server control.

You could use a smart control that loads the user control from a common location, SharePoint uses this method with Visual WebParts, however, you would need to have the assembly containing the user control's code deployed to the GAC so it would be available from sub projects.
 
Share this answer
 
Comments
Monjurul Habib 29-Jul-11 15:20pm    
good advice.5+
Shahriar Iqbal Chowdhury/Galib 29-Jul-11 17:11pm    
good answer
Simple. :) Just add your User Control(ascx) file as existing file and compile with your sister site. How ?

1. Right click in your sister site project.
2. Select Add Existing file.
3. Locate where the User Control(ascx) file exists and select the file including the code behind file.(i.e. usercontrol.ascx.cs)

I hope this helps you well.
 
Share this answer
 
Comments
[no name] 31-Jul-11 19:32pm    
This isn't reusability and may cause versioning issue in the future.
Wonde Tadesse 31-Jul-11 20:04pm    
I don't think the OP asks reusability. If he was, I would suggested him to convert the user control to Server Control library. :) For YUI it won't cause versioning issue, Visual Studio will take care of it.
[no name] 1-Aug-11 8:03am    
We should be suggesting proper techniques regardless of whether the OP asks or not. And, yes, there will be versioning issues. With this type of sharing you don't have the possibly to modify the control for a different usage, all project will use the same one. With a server control however you can have different versions of the assembly, and side-by-side in some cases.
Wonde Tadesse 1-Aug-11 8:13am    
I understand the term "reusability". Let me give you other term "SOLID". But I don't think you clearly differentiate ASCX and Server control. The OP want to use existing ASCX controls. That is all.

" With this type of sharing you don't have the possibly to modify the control for a different usage, all project will use the same one", why not ? As long as the OP adds the ASCX file and associated class to the project, he can modify the User Control as he wants.
[no name] 1-Aug-11 22:27pm    
I don't believe you understand the term, copying files is not reuse.

Yes, if there are separate files in separate projects they are independent. However, now a change must be applied in two, or more, places, making for a maintenance nightmare. That is not reuse.

Although, the files could be linked from a shared folder it does not give the ability to modify the files independent of the project. Both projects would use the same file. On the other hand, a server control could be versioned separately, each project could reference a separate version and have its own version in the local bin folder, or two versions could live side-by-side. The ASP.NET controls are not ascx files that you copy into each project now are they? Is that "SOLID" enough for you? Do you understand now?

Yes, the OP asked about ascx files, yet, as I have pointed out, it is our responsibility to not just answer the question but also to show correct techniques.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900