Copied to clipboard

Flag this post as spam?

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


  • Frank van Rooijen 7 posts 27 karma points
    Mar 02, 2010 @ 16:55
    Frank van Rooijen
    0

    Custom Section with multiple trees and actions

    I created a custom section which loads a tree. The root tree has two nodes.

    The create action on the two main nodes should preform a seperate action. So far I have this:

            public override void Render(ref XmlTree tree) {
                if (string.IsNullOrEmpty(this.NodeKey)) {
                    //Add the first level
                    XmlTreeNode xNodeProfileKeywords = XmlTreeNode.Create(this);
                    xNodeProfileKeywords.NodeID = "manageProfileKeywords";
                    xNodeProfileKeywords.NodeType = "manageProfileKeywords";
                    xNodeProfileKeywords.Text = "Profiel sleutelwoorden";
                    xNodeProfileKeywords.Icon = "folder.gif";
                    xNodeProfileKeywords.HasChildren = true;
                    xNodeProfileKeywords.Source = this.GetTreeServiceUrl(xNodeProfileKeywords.NodeID);
                    xNodeProfileKeywords.Menu.Clear();
                    xNodeProfileKeywords.Menu.AddRange(new List<IAction>() { ActionNew.Instance });
                    tree.Add(xNodeProfileKeywords);

                    XmlTreeNode xNodeCompanies = XmlTreeNode.Create(this);
                    xNodeCompanies.NodeID = "manageStringTranslations";
                    xNodeCompanies.NodeType = "manageStringTranslations";
                    xNodeCompanies.Text = "Vertaalbare tekst";
                    xNodeCompanies.Icon = "folder.gif";
                    xNodeCompanies.HasChildren = true;
                    xNodeCompanies.Source = this.GetTreeServiceUrl(xNodeCompanies.NodeID);
                    xNodeCompanies.Menu.Clear();
                    xNodeCompanies.Menu.AddRange(new List<IAction>() { ActionNew.Instance });
                    tree.Add(xNodeCompanies);

                } else if (this.NodeKey == "manageProfileKeywords") {
                    using (MyHypothekerUmbracoEntities rep = new MyHypothekerUmbracoEntities()) {
                        var allProfileKeywords = rep.ProfileKeywordSet.OrderBy(pk => pk.Keyword);
                        foreach (var profileKeyword in allProfileKeywords) {
                            XmlTreeNode xNode = XmlTreeNode.Create(this);
                            xNode.NodeID = profileKeyword.ProfileKeywordID.ToString();
                            xNode.Text = profileKeyword.Keyword;
                            xNode.Icon = "hyp_profiles_16.png";
                            xNode.Action = "javascript:openProfileKeyword('" + xNode.NodeID + "')";
                            tree.Add(xNode);
                        }
                    }
                } else if (this.NodeKey == "manageStringTranslations") {
                    using (MyHypothekerUmbracoEntities rep = new MyHypothekerUmbracoEntities()) {
                        var allReplacements = rep.StringReplacementItemSet.OrderBy(r => r.StringReplacementKey);
                        foreach (var replacement in allReplacements) {
                            XmlTreeNode xNode = XmlTreeNode.Create(this);
                            xNode.NodeID = replacement.StringReplacementId.ToString();
                            xNode.Text = replacement.StringReplacementKey;
                            xNode.Icon = "hyp_profiles_16.png";
                            xNode.Action = "javascript:openStringTranslation('" + xNode.NodeID + "')";
                            tree.Add(xNode);
                        }
                    }
                }    
            }

     

    In the UI.XML I tried to add this code to make teh magic happen:

        <nodeType alias="manageProfileKeywords">
            <header>Profile keywords</header>
            <usercontrol>/create/simple.ascx</usercontrol>
            <tasks>
                <create assembly="TamTam.Umbraco.Exensions" type="Sections.Custom.Tasks.ProfileKeywordsTasks" />
                <delete assembly="TamTam.Umbraco.Exensions" type="Sections.Custom.Tasks.ProfileKeywordsTasks" />
            </tasks>
        </nodeType>
        <nodeType alias="manageStringTranslations">
            <header>String translations</header>
            <usercontrol>/create/simple.ascx</usercontrol>
            <tasks>
                <create assembly="TamTam.Umbraco.Exensions" type="Sections.Custom.Tasks.StringTranslationsTasks" />
                <delete assembly="TamTam.Umbraco.Exensions" type="Sections.Custom.Tasks.StringTranslationsTasks" />
            </tasks>
        </nodeType>

    But when I call the create a new item from the subroot items I get the following message

    Server Error in '/' Application.

    Input string was not in a correct format.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.FormatException: Input string was not in a correct format.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [FormatException: Input string was not in a correct format.]
    System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7469351
    System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
    umbraco.cms.presentation.create.controls.simple.sbmt_Click(Object sender, EventArgs e) +93
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

    Anyone has any idea if this is the right way to go, what I am doing wrong or have another idea.

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Mar 02, 2010 @ 20:00
    Morten Christensen
    0

    Hi Frank,

    First off, looks like you are trying to Parse a string to an integer but something goes wrong - maybe your string is not a number (maybe because you are not hitting your usercontrol)?

    Have you tried debugging to see what goes on in your usercontrol? And whether your Create action hits the right usercontrol (this is the standard umbraco create control right: <usercontrol>/create/simple.ascx</usercontrol>)?

    Does the create action actually work on the rootnode or is it both root and subnode thats not working?

     

    - Morten

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Mar 02, 2010 @ 20:07
    Morten Christensen
    0

    Hi again,

    Here is the code that is throwing the exception in the simple.ascx usercontrol:

    int nodeId = -1;
    if (umbraco.helper.Request("nodeId") != "init")
    nodeId = int.Parse(umbraco.helper.Request("nodeId"));

    Thought it might help you in the right direction - as you can se the "nodeId" querystring is parsed to an integer, which seems to fail.

    Could it be these two nodes that are causing you problems (?):

     xNodeProfileKeywords.NodeID = "manageProfileKeywords";

    xNodeCompanies.NodeID = "manageStringTranslations";

    - Morten

  • Frank van Rooijen 7 posts 27 karma points
    Mar 03, 2010 @ 10:50
    Frank van Rooijen
    0

    Hi Morten,

    Thanks for your reply, it really helped to solve the problem. Underneath my solution.

    I gave the NodeID's for my second level items a string value because the rootnode has the value "init'. So I didn't think it should cause an issue. But you were right that this caused the issue. To make a workaround I decided to create a new page, to handle the creation of an new item.

    So my UI.xml will look something like this:

        <nodeType alias="manageProfileKeywords">
            <header>Profile keywords</header>
            <usercontrol>/create/dbitem.ascx</usercontrol>
            <tasks>
                <create assembly="TamTam.Umbraco.Exensions" type="Sections.Custom.Tasks.ProfileKeywordsTasks" />
                <delete assembly="TamTam.Umbraco.Exensions" type="Sections.Custom.Tasks.ProfileKeywordsTasks" />
            </tasks>
        </nodeType>
        <nodeType alias="manageStringTranslations">
            <header>String translations</header>
            <usercontrol>/create/dbitem.ascx</usercontrol>
            <tasks>
                <create assembly="TamTam.Umbraco.Exensions" type="Sections.Custom.Tasks.StringTranslationsTasks" />
                <delete assembly="TamTam.Umbraco.Exensions" type="Sections.Custom.Tasks.StringTranslationsTasks" />
            </tasks>
        </nodeType>

    I copied the code from simple.ascx.cs to my dbitem.ascx.cs and changed the code to:

    int nodeId = -1;
    int.TryParse(U.helper.Request("nodeId"), out nodeId);

    This will make everything work as it should.

    Maybe this code could be placed in the next release, to fix these kind of problems.

    Thanks agian.
    - Frank

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Mar 03, 2010 @ 13:57
    Morten Christensen
    0

    Hi Frank,

    Glad I could help.
    Please mark one of the answers as solution, so others can see there is a solution to this issue - and thanks for sharing your solution ;)

    - Morten

  • Max 144 posts 166 karma points
    May 28, 2012 @ 12:57
    Max
    0

    what about UmbracoApp table setting do you need to do anythign regarding that

     

  • Max 144 posts 166 karma points
    May 30, 2012 @ 13:01
    Max
    0

    Hi I created my own Control However the delete function is not working it gives me object not set to a refence of an object error. 

    how to solve this

     

     

  • Max 144 posts 166 karma points
    Jun 01, 2012 @ 08:40
    Max
    0

    the delete is not working it give me this error

    Error handling action

    Object reference not set to an instance of an object

     

     

Please Sign in or register to post replies

Write your reply to:

Draft