Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web User Control Library

We have a bunch of user controls we would like to pull out of a web application and into a separate assembly/library, and I thought it would be as simple as creating a class library and pulling the ascx and ascx.cs files into the project, and compiling a DLL to be reused among our applications.

This was not the case, however.

Our ultimate goal is to have a single distributable DLL (similar to how Telerik distributes their controls) that we can throw into any web application. The steps here: Turning an .ascx User Control into a Redistributable Custom Control were very simple to follow, however this results in many files named controlname.ascx.guid.dll, which is not the desired result. I couldn't even get these to work anyways, since we have additional classes that need to be compiled into the assembly.

Has anyone successfully created a web user control library in .NET (we're using 3.5 here)? I can't seem to find a nice step-by-step guide.

like image 360
Keith Avatar asked Aug 14 '09 22:08

Keith


People also ask

What is ASP.NET custom Web control?

What Does Custom Control Mean? Custom control is a control that is not included in the . NET framework library and is instead created by a third-party software vendor or a user. Custom control is a concept used while building both Windows Forms client and ASP.NET Web applications.

How do I add user control to my library?

Right click the project in the Solution Explorer and select Add > User Control…. In the dialog that appears, name the user-control file and click Add. Inside the project, add controls and functionality to the UserControl ( here I added 2 radiobuttons(Bold, Italic) and.

What is user control in ASP.NET c#?

A User Control is a reusable page or control with an extension of . ascx and created similar to an . aspx page but the difference is that a User Control does not render on its own, it requires an . aspx page to be rendered. User Controls are very useful to avoid repetition of code for similar requirements.


2 Answers

I realize this is an old topic, but if anyone is looking for a solution for creating reusable user control libraries, it turns out it's fairly simple. Here are two good step-by-step guides along with source code:

From MSDN: Turning an .ascx User Control into a Redistributable Custom Control

From Code Project: Straight way to create ASP.NET user controls library

The second link provides a solution to the multiple dlls created by the first link.

Edit- (2) Seems to be a dead link. Here's the new link

https://www.codeproject.com/Articles/30247/Straight-way-to-create-ASP-NET-user-controls-libra

like image 73
0x1mason Avatar answered Nov 02 '22 07:11

0x1mason


If you want to share controls among project, my experience has shown that the best way is to build custom asp.net server controls instead of usercontrols. User controls are good for sharing within the same project, but not over multiple ones.

For this purpose I suggest you to build a set of custom server controls inside a class library and use that on all of your projects.

This book does quite a good job at explaining the basics of creating server controls

Edit:
I'm currently developing a .net web server control library. I actually didn't follow any step-by-step guide. I mostly considered using the book I mentioned above and the MSDN library + Reflector, which is a great tool for inspecting existing MS server controls and learning from them.

like image 24
Juri Avatar answered Nov 02 '22 06:11

Juri