Copied to clipboard

Flag this post as spam?

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


  • Roger 195 posts 474 karma points
    May 09, 2013 @ 14:28
    Roger
    0

    Usercontrol Error help please!

    Hi all,

    I have a usercontrol that needs to add content programmatically from the front end. It basically needs to write a 'note' to the 'Notes' node within the current page. The usercontrol is giving me an error and I think it is an issue in the code. Here's the code behind:

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

        public partial class usercontrols_WebUserControl : Umbraco.Web.UmbracoUserControl
        {
            protected void create(object sender, EventArgs e)
            {
                //Get the current page ID
                var pageId = UmbracoContext.PageId.Value;

                //get the content service from this.UmbracoContext.Application.Services
                var cs = Services.ContentService;


                //Create content, pass in the parent id and the document type alias.
                var document = cs.CreateContent("Status-" + DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture),
                                                pageId,
                                                "StatusUpdate");

                //Set the post propety
                document.SetValue("post", post.Text);

                //Set the author ID
                document.SetValue("memberId", Member.GetCurrentMember().Id);


                cs.Publish(document);

            }
        }

     

    I am getting:

    Error creating control (~/usercontrols/AddNote.ascx).
    Maybe file doesn't exists or the usercontrol has a cache directive, which is not allowed! See the tracestack for more information!

    The tracestack:

    System.Web.HttpCompileException (0x80004005): c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl). at System.Web.Compilation.AssemblyBuilder.Compile() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath) at umbraco.developer.assemblyBrowser.Page_Load(Object sender, EventArgs e)

    Can someone please help with this?

    Thanks in advance!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 09, 2013 @ 14:35
    Jan Skovgaard
    0

    Hi Roger

    I assume you have a macro that renders on a template or from withing a rich text editor on the frontend. Is this macro mapped corretly to the user control? And does the user control exist in the usercontrol folder in your umbraco installation?

    Have you made a project, which uses xcopy to copy over the assemblies to the bin folder and user controls to the usercontrol folder?

    Looking forward to hearing from you.

    /Jan

  • Roger 195 posts 474 karma points
    May 09, 2013 @ 14:42
    Roger
    0

    Hi Jan,

    Thanks for your swift reply!

    The macro is there and the usercontrol is mapped to it. The usercontrol exists in the usercontrols folder.

    I've not made a project no.

    I opened my Umbraco site in VS 2010 and added a usercontrol from there. The only files I had were the usercontrol and code behind.

    Have I done something incorrect here?

    Thanks

  • Roger 195 posts 474 karma points
    May 09, 2013 @ 14:44
    Roger
    0

    The other thing is, how does the code above know what node to add the note to?

    Sorry, Tim helped me initally with it. I'm new to adding data programmatically in Umbraco :-/

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 09, 2013 @ 14:56
    Jan Skovgaard
    0

    Hi Roger

    Ok...since I'm a frontend guy on a dauly basis it's been a while since I've been having a look at user controls and c# code. I know I've seen this error before...

    Try adding ?umbdebugshowtrace=1 to the url of the page your'e requesting and see if we get some more information in the stack trace. Also try having a look in the umbracoLog table and see if the reveals anything of interest.

    It's usualy caused by some missing dll files...just hard to figure out what it can be.

    The code looks fine to me at a first glance.

    It know where to add the new node because it gets the page id of the current node in this variable

    //Get the current page ID
                var pageId = UmbracoContext.PageId.Value;

    The "CreateContent" method takes this PageId as the parameter to figure out, which node the content should be created beneath.

    Hope this makes sense? :)

    /Jan

  • Roger 195 posts 474 karma points
    May 09, 2013 @ 15:05
    Roger
    0

    Hi Jan,

    The stack trace is:

    System.Web.HttpCompileException (0x80004005): c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl). at System.Web.Compilation.AssemblyBuilder.Compile() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath) at umbraco.developer.assemblyBrowser.Page_Load(Object sender, EventArgs e)

    I'm pretty stuck on what files I might have missing.

    I only really have the usercontrol with the codebehind

    I think the code behind is inheriting correctly but I could be wrong

    Roger

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 09, 2013 @ 15:56
    Jan Skovgaard
    0

    Aaah sorry I totally missed that you already had added the stack-trace. H5IS :)

    What DLL's have you included? And do you get any build errors or warnings?

    /Jan

  • Roger 195 posts 474 karma points
    May 09, 2013 @ 16:10
    Roger
    0

    Hi Jan,

    No dll's I just created the control in VS2010 and added the ascx and cs files

  • Roger 195 posts 474 karma points
    May 09, 2013 @ 16:14
    Roger
    0

    Hi Jan,

    No build errors that relate to the usercontrol at all

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 09, 2013 @ 16:28
    Jan Skovgaard
    0

    Could you search the entire project to see if there is a AddNote.dll in the folder somewhere, which needs to be copied to the /bin folder of Umbraco?

    The .dll file is created once you build your project so it's not something you add yourself. I'm feeling somewhat confident it's because this is missing from the bin folder that you get the error above.

    Hope this helps.

    /Jan

  • Roger 195 posts 474 karma points
    May 09, 2013 @ 17:16
    Roger
    0

    Hi Jan,

    I just created a new project called AddNote and then added a new item, web usercontrol and called that AddNote

    I then built the project to create the dll.

    If I add all the umbraco references in the code behind it wont build because this is just a standard project to make the user control and it doesnt have all the umbraco assemblies.

    I copied the dll into the bin folder on my umbraco site, cleared the cache and rebuilt the site.

    The error is still the same.

    It's telling me that there is an inheritence issue in the stack trace

    System.Web.HttpCompileException (0x80004005): c:\inetpub\wwwroot\iccm.uk.com\usercontrols\AddNote.ascx.cs(9): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

    is the dll just to register the usercontrol? If so, can I just do this in the web.config?

    It's driving me mad, simple usercontrol and i can't get it working :-/

  • Roger 195 posts 474 karma points
    May 09, 2013 @ 17:22
    Roger
    0

    I think there may be an error in this section of the code behind:

    using Umbraco.Web;
    using Umbraco.Web.UI;
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.web;

    namespace umbracoDocumentApi
    {
        public partial class usercontrols_WebUserControl : Umbraco.Web.UmbracoUserControl

Please Sign in or register to post replies

Write your reply to:

Draft