locked
build ascx files into a dll RRS feed

  • Question

  • User332411063 posted

    I'm using VS 2008 with asp.net 3.5.  I am trying to figure out a way to build my library of ascx files into a dll.  I've used the web deployment project to merge all output to a single assembly and unchecked "allow this precompiled site to be updatable".   However, the result is a  dll with stubbed out ascx pages. 

    Is there any way to remove the stubbed out ascx files?  And if not, is there a way to place only the ascx files into a known directory ("C: Program Files/My Company/My Product/...") for the deployed web application to access? 

    Essentially, I need to be able to deploy multiple instances of the web application onto a  machine with only one instance of the code behind dll and ascx files (dll in the GAC and ascx files either contained in the dll or shared in a known location).

    thank you

    Tuesday, March 4, 2008 11:02 AM

Answers

All replies

  • User-2074625069 posted

    You could convert your usercontrols into custom controls and store the assemblies in the GAC:

    Turning an .ascx User Control into a Redistributable Custom Control
    http://msdn.microsoft.com/en-us/library/aa479318.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 4, 2008 11:34 AM
  • User332411063 posted

    Excellent tutorial.  The only problem is that I can't get the user control to display on my page.  I've registered the user control dll with the GAC.  In my aspx page, I register the user control using the following line:

    %@Register TagPrefix="tst" Namespace="ControlLibrary" Assembly="ControlLibrary"%

     in my form I add the user control:

    <tst:UserCtrl ID="LoginPage1" Visible="true" runat="server" />

    I can also reference the user control in my code behind.  The new problem is that the control is hidden when I run the web app...

    Do you think it has something to do with the ascx files not being included in the web directory?  The instructions say to precompile the ascx project without making it updateable, so I'm assuming that this isn't the problem. 

    Any additional help would be greatly appreciated

    Tuesday, March 4, 2008 5:19 PM
  • User-762694769 posted

    If you are putting the assembly in the GAC, you will need to specify its full name when you reference it. That is, with the version and public key token.

    Have you tried NOT putting in the GAC to see whether it works as described in the article? I would recommend you making sure that your control is working first following the steps in the article before trying to put it into the GAC.

    Wednesday, March 5, 2008 12:28 PM
  • User332411063 posted

    I'm getting the same functionality with/without registering to the GAC.  My web app will build however, the user control is missing/hidden when running in the web browser.

    I bet my issue lies somewhere with the namespace/classname.  Here's a little more info on my setup:

    My User Controls will exist in a project called ControlLibrary.  Building the project will produce ControlLibrary.dll.  Below is the declaration tag of the user control UserCtrl.ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserCtrl.ascx.cs" ClassName="ControlLibrary" Inherits="ControlLibrary.UserCtrl" %>

    And this is how I use it in my aspx page:

    <%@Register TagPrefix="Acme" Namespace="ControlLibrary" Assembly="ControlLibrary"%>

    <Acme:UserCtrl id="MyUC" runat="server"/>

     ---------------------

    I've also tried using a ClassName of "Acme.UserCtrl" with a Namespace of "Acme".

    thanks for looking into this issue for me

     

    Wednesday, March 5, 2008 1:14 PM
  • User-762694769 posted

    For the project that builds your control, are you using a Web Application Project or a Web Site? You need to use a Web Site so that both the ascx and ascx.cs gets compiled into the assembly. If you just use a Web Application Project, then only the ascx.cs gets compiled into the assembly.

    Thursday, March 6, 2008 1:06 PM
  • User775852626 posted

    We set up as mentioned in the article - We created it in a website, set the namespace and everything. In the Hostapplication we created the links. Everything works fine, even our custom property will be displayed in the designer.

    But if we are running the website, we'll don't see anything - As soon as we set our custom property Description we get a NullReferenceException.

    What's wrong?

    Is there any demo source code available?

    Here are the files we created (in a "Website"):

    FieldItem.ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="FieldItem.ascx.cs" ClassName="InhouseWKOIT.ControlKit.FieldItem" Inherits="FieldItem" %>
    <asp:Label runat="server" ID="myLabel" />

    FieldItem.ascx.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class FieldItem : System.Web.UI.UserControl
    {

        public string Description
        {
            get
            {
                return myLabel.Text;
            }
            set
            {
                myLabel.Text = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {


        }
    }

    And this is from the consuming "Web Project"

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HostApplication._Default" %>
    <%@ Register TagPrefix="Acme" Assembly="App_Web_fielditem.ascx.cdcab7d2" Namespace="InhouseWKOIT.ControlKit"%>

    <!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></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <Acme:FieldItem runat="server" ID="test" Description="MyTest" />

    </div>
    </form>
    </body>
    </html>


    So what's wrong?

    Thursday, February 25, 2010 5:25 AM
  • User775852626 posted

    Sorry, something happend when copy the code it looks like. here again:

    -----------------

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="FieldItem.ascx.cs" ClassName="InhouseWKOIT.ControlKit.FieldItem" Inherits="FieldItem" %>
    <asp:Label runat="server" ID="myLabel" />

    ---------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class FieldItem : System.Web.UI.UserControl
    {

        public string Description
        {
            get
            {
                return myLabel.Text;
            }
            set
            {
                myLabel.Text = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {


        }
    }

    --------------

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HostApplication._Default" %>
    <%@ Register TagPrefix="Acme" Assembly="App_Web_fielditem.ascx.cdcab7d2" Namespace="InhouseWKOIT.ControlKit"%>

    <!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></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <Acme:FieldItem runat="server" ID="test" Description="MyTest" />
           
        </div>
        </form>
    </body>
    </html>




    Thursday, February 25, 2010 5:27 AM
  • User-762694769 posted

    Maybe you could try the example given in the article first to understand how it works before trying to apply it on your own web site.  You can look into the stack trace when the nullReferenceException is thrown to see where in the code it is happening.

    Friday, February 26, 2010 12:48 PM
  • User775852626 posted

    We did try the sample of the article of course, which doesn't work. Unfortunately this doesn't work? There's also no source code provided there to see what's the difference. Where can I find a working sample to download?

    Did you try the one I posted? The NullReference ic caused by the Label Control which is null but it shouldn't be

    Thanks a lot,

    dominik


    Saturday, February 27, 2010 5:15 AM
  • User775852626 posted

    No one any ideas? :-(

    Wednesday, March 3, 2010 4:25 AM
  • User736055083 posted

    hi I have .ascx web user control in my web site.

    Now I want to make dll for that .ascx file

    Plese let me know steps how can I make .dll file for that .ascx web user control.

    Please help me out to solve this issue..


    regards,

    Ankit Champaneriya

    Wednesday, December 15, 2010 6:27 AM
  • User-153022205 posted

    I am having the same issue, could you please share if you were able to solve the problem.

    Tuesday, April 30, 2013 11:38 PM