Compile User controls to dynamic link libraries

Last post 07-22-2008 3:55 AM by ingljo. 2 replies.

Sort Posts:

  • Compile User controls to dynamic link libraries

    07-18-2008, 9:15 AM
    • Member
      5 point Member
    • ingljo
    • Member since 01-04-2008, 2:13 AM
    • Oslo
    • Posts 9

    Hi,

    I have created a set of generic UserControls that i plan to use in various websites.

    From the article http://msdn.microsoft.com/en-us/library/aa479318.aspx it looks like it is possible to compile the user-controls into a re-usable custom controls and add them as dll-libraries in my other web-sites.

    But when i try to test a user-control by the design mentioned in the article, I get null-ponter exceptions.

    Have anyone done this before, and is this a design-pattern that is normal to use, or should I re-write the code to ServerControls?

    Web.config:
    <pages>
    <controls>
    <add tagPrefix="uc" namespace="TestUserControls" assembly="TestUserControls"/>
    </controls>
    </pages>
    Default.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="TestUserControls.Default2" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <uc:TestControl id="test2" runat="server" />
    </div>
    </form>
    </body>
    </html>

    TestControl.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="TestUserControls.TestControl" %>
    <asp:Label ID="lblTest" runat="server" />

    TestControl.ascx.cs

    namespace TestUserControls
    {
    public partial class TestControl : System.Web.UI.UserControl
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    lblTest.Text = "Test"; <-- Get null-ponter exception here
            }
    }
    }
  • Re: Compile User controls to dynamic link libraries

    07-18-2008, 10:49 AM
    Answer
    • Participant
      1,266 point Participant
    • dswersky
    • Member since 06-18-2008, 3:45 PM
    • Posts 218

    I have actually tried the steps in that article and found it to be less than accurate or helpful.  It is possible to load pages and usercontrols from an assembly.  Here is a good KB Article:

     http://support.microsoft.com/kb/910441/en-us?spid=8940&sid=global

    Here is a CodeProject writeup on the subject:

    http://www.codeproject.com/KB/aspnet/ASP2UserControlLibrary.aspx

  • Re: Compile User controls to dynamic link libraries

    07-22-2008, 3:55 AM
    Answer
    • Member
      5 point Member
    • ingljo
    • Member since 01-04-2008, 2:13 AM
    • Oslo
    • Posts 9

     Hi, thanks for the helpful articles! Smile

     I actually got the best solution by using the CodePlex Web Application Project Libraries (http://www.codeplex.com/wapl).

     By adding the wapl.exe merge tool in the user-library project's Post-build event, I got a working dll that I could implement easily in other web applications.

     

     

Page 1 of 1 (3 items)