Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • North Krimsly 59 posts 80 karma points
    Aug 04, 2010 @ 23:47
    North Krimsly
    0

    User control - DLL needed, or just .ascx and .ascx.cs files?

    Greetings all,

    I created a .Net user control to be used with a macro, and placed the DLL into /bin and the .ascx file into /usercontrols.  That failed to load the user control.  Umbraco debug mode told me it needed the .ascx.cs code-behind file. So I copied the .ascx.cs file into /usercontrols as well.

    Then I deleted the user control .DLL from /bin.  The control now works great without the DLL.  Hmmm. Does this mean user control DLL's are not needed- you just need the .ascx and .ascx.cs files?  Or does it mean that I did something wrong in my build of the user control, and I should be using the .DLL but not the .ascx.cs file?

    Your help in understanding how this works would be appreciated.

    Thanks,

    -NorthK

  • Sascha Wolter 615 posts 1101 karma points
    Aug 05, 2010 @ 00:33
    Sascha Wolter
    0

    Basically you have web sites and web applications in .Net. The latter ones get precompiled into dlls and you need pretty much the ascx files which contain the Html etc and the dlls to run the site (over simplified). Web sites don't get compiled before deployment, you deploy the ascx and code-behind files to the server and the first time somebody makes a request to your site it gets compiled on the server. The biggest difference between the two methods is that you don't have the compile on the initial request with web application, because after that they are pretty much the same. You have obviously much more control over things if you pre-compile your web application and you will get more error messages which are found during the compile process.

    That said the Umbraco binaries are a web application, pre-compiled aka ascx + dlls (and some bits and pieces more). But that doesn't say anything about the method of how you deploy your own additional code. By accident I once forgot to copy over a dll and just copied over the whole ascx/code-behind/designer file batch and realised only after it worked that I couldn't have deployed the dll - yet it worked fine as your additonal code gets compiled automatically upon the next request. That said: adding ascx and dlls should always work as well, so I have no idea why it didn't for you, that's a bit odd.

    So in general: both ways should work fine, I personally like to pre-compile my own code before deployment because of the additional error messages I get.

    Sascha

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Aug 05, 2010 @ 00:40
    Stefan Kip
    0

    What's your usercontrol's page directive?
    It should look like this:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UsercontrolName.ascx.cs" Inherits="Some.Fancy.Namespace.UsercontrolName" %>

    Look out it's not using CodeFile instead of CodeBehind...

  • North Krimsly 59 posts 80 karma points
    Aug 05, 2010 @ 01:35
    North Krimsly
    0

    Sascha,

    Thanks for a great explanation. I think I probably built the DLL wrong.  I chose Web Site as the type of project in Visual Studio, rather than Web Application.  I then added a new Web User Control to the Web Site.  I didn't have a /bin directory for my project which I thought was strange, until I Published the site in Visual Studio as "precompiled". I then tried to use the DLL that Visual Studio published.

    So I think it's my lack of familiarity with how Visual Studio works.  I think I should have chosen Web Application for the type of project to begin with, and that should have given me a /bin directory along with a proper DLL.

    kipusoep, I do seem to have the wrong page directive: mine looks like:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="WebUserControl" %>

    This is the page directive Visual Studio gave me when I told it to add a new Web User Control to the project. Is that because I chose Web Site rather than Web Application as the project type? I don't understand the difference between the two types of directives, or why Visual Studio would give me the wrong one.

    Thanks very much to both of you for your help.

    -NorthK

     

Please Sign in or register to post replies

Write your reply to:

Draft