After sketching the problem of creating User Control Libraries in VS 2010 and various ways to solve it (some of them no longer supported or cumbersome to use), here is a solution that works in VS2010.
We start with a web application project containing a couple of ascx controls, and migrate them into a library.
First, we create a Class Library project and implement a base class which loads the information contained in the ascx and instantiates a Control:
public class UserControl : System.Web.UI.UserControl
{
protected override void FrameworkInitialize()
{
base.FrameworkInitialize();
string content = String.Empty;
Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(GetType(), GetType().Name + ".ascx");
using (StreamReader reader = new StreamReader(stream))
{
content = reader.ReadToEnd();
}
Control userControl = Page.ParseControl(content);
this.Controls.Add(userControl);
}
}
Screenshot of web application and user control library in a VS solution:

A simple user control containing only text and markup, such as
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="mySimple_org.ascx.cs" Inherits="MyCtrlWeb.mySimple" %>
this is my simple control
can be converted into a library-based control in these steps:
- delete the designer.cs file
- empty the .ascx.cs file (the .ascx.cs file needs to exist, otherwise the compiler will issue a file not found error)
<%@ Control Language="C#" %>
this is my simple control
For users controls containing other controls and program code, perform the following operations:
- copy the ascx from the web application to the user control library
- change the Build Action of the .ascx file from Content to Embedded Resource
- remove all attributes in the Control declaration
<%@ Control Language="C#" %>
this is my <asp:Label runat="server" ID="label">Label</asp:Label> control
- create a .cs file with the same name as the .ascx (i.e., for the control myLabel.ascx, create a myLabel.cs file)
- derive the newly created class from the UserControl class loading the ascx
public partial class myLabel : UserControl
{
- copy the member declaration of the contained controls from the .designer.cs file, and subsequently delete .designer.cs
protected global::System.Web.UI.WebControls.Label label;
- retrieve references to the controls contained in the ascx in the control’s FrameworkInitialize() method
protected override void FrameworkInitialize()
{
base.FrameworkInitialize();
label = (Label)this.FindControl("label");
}
- cut and paste the control’s code-behind into the newly created class, and leave the original code-behind file empty
- add reference to the library in the web project
- embed the new control in a web form
<%@ Register TagPrefix="my" Assembly="MyWebCtrls" Namespace="MyWebCtrls" %>
<my:mySimple runat="server" id="c1"></my:mySimple>
<my:myLabel runat="server" id="c2"></my:myLabel>
- optionally, add system.web/compilation/assemblies/add assembly and system.web/pages/controls/add tagPrefix settings to your web.config
- execute
My sample page
this is my page
<h2>hi</h2>
<my:mySimple runat="server" id="c1"></my:mySimple>
<h2>hey</h2>
<my:myLabel runat="server" id="c2"></my:myLabel>
<h2>bye</h2>
will then be rendered like this:

Sample code is available for download.