You can move your SpiffyControl to the library - this will give it a more accurate namespace and also allow you to use it in other projects. This is a bit complicated, but you already have UserControl installed, but it will not work in the library. UserControls uses the codebehind model - they consist of two files, one markup and one code. Libraries do not seem to support the codebehind model, so you cannot use UserControl. You need to convert this user control to a web control.
Create a new class library project. Open the project properties and set the AssemblyName and default namespace to SpiffyLibrary.
Now we need to convert your UserControl. First create a class in your new library. Call it SpiffyControl, like an existing user control, but inherit it from System.Web.UI.WebControls.CompositeControl.
Secondly, open the code of an existing user control and copy everything inside the class. Then go back to the new class and paste it inside. If you use any standard control events, you may need to rename these functions to override the corresponding events. For example,
protected void Page_Load(object sender, EventArgs e) { ... }
... must become ...
protected override void OnLoad(EventArgs e) { ... base.OnLoad(e); }
Third (this is the hard part) you need to reproduce all the markup you had in the SpiffyControl markup file. You can't just copy it - instead, you need to override the CreateChildControls () function, which is inherited from CompositeControl. Each tag that you had in the markup should be created as a variable and added to the Controls collection of the class. For example, if your existing markup file looks like this:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SpiffyControl.ascx.cs" Inherits="Controls_SpiffyControl" %> <div id="Div1" runat="server"> <asp:Label ID="TextOutput" runat="server" /> </div>
... then your new CreateChildControls function should look like this:
HtmlGenericControl Div1; Label TextLabel; protected override void CreateChildControls() { Div1 = new HtmlGenericControl("div"); this.Controls.Add(Div1); TextLabel = new Label(); Div1.Controls.Add(TextLabel); base.CreateChildControls(); }
Note that controls are declared as class fields; Thus, they are visible to all class methods.
Once you convert your markup, compile the library project and add it to the links for your website project. Then open the web.config file and find the system.web / pages / controls section. This section should already have a tag:
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
This tag allows you to use controls from major ASP libraries. Therefore, we are going to add it in the same way as for our library:
<add tagPrefix="spiffy" namespace="SpiffyLibrary" assembly="SpiffyLibrary" />
Now, anywhere in your site, you can add markup as follows:
<spiffy:SpiffyControl ID="SpiffyInstance" runat="server" />
... and this will load your web control from your user library.