Link to home
Start Free TrialLog in
Avatar of dpbouchard
dpbouchardFlag for United States of America

asked on

ASP.NET 4.0 Web User Control (ascx) Library???

I have a handful of different websites. These websites are different is every aspect except for 1 function. This function involves a form with about a dozen or so fields. This form also looks and operates exactly the same on each website.

Instead of having the html and code for these forms duplicated on every site, I would like to create a "Web User Control" library in Visual Studio 2010. Without really hacking some things up, I cannot find a simple way to do this. I can create a custom Server Control library but since these forms contain multiple other controls, html and functionality, it would be really tedious.

I found one example where you create an empty "Web Application" project and add your ascx files in there. You then reference the published dll. This would actually work except for the ascx files themselves have to be copied over into each referencing web project.

Does anyone have any ideas? I find it hard to believe that Microsoft would not have included this ability.
ASKER CERTIFIED SOLUTION
Avatar of AngryBinary
AngryBinary

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dpbouchard

ASKER

Thanks AB, I will give this a try in the morning. I basically tried this same approach but with a Web Application not a Web Site.
AngryBinary, all looked like it was going to go well but I got the following when I ran the project.

Could not load file or assembly 'Testing' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

FYI... For testing purposes I used "MyNamespace.MyControl" for the ClassName attribute. And I renamed the actual dll to "Testing". When I reference that dll in the project it actually shows up as "Testing" and "Testing" shows up in the error above.

This happens by just referencing the dll before adding any code the the source project.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AngryBinary
AngryBinary

That does make sense, actually. Try it without renaming the assembly to make sure that it works. If you want to rename the assembly after that, you have to disassemble and edit the manifest to match.
That did it! Thanks a lot!!!

Would editing the manifest be difficult?
It's not phenomenally difficult. Visual Studio comes with the tools you need, and it's just a couple of command line arguments that need to be made. Look at the example provided here:

http://www.codeproject.com/KB/msil/ManifestEdit.aspx

They don't address changing the assembly name specifically, but I think all you'd have to do is change "SatelliteAssembly" (the name of the assembly in their example) to whatever you want to name it in the following line of IL code:

.assembly /*20000001*/ SatelliteAssembly