Copied to clipboard

Flag this post as spam?

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


  • Rahul 12 posts 83 karma points
    Mar 25, 2014 @ 06:55
    Rahul
    0

    Create Tree Under Custom Section with Form to entry Announcements by Admin

    Hi Everyone,

    I succesfully created custom section in Umbraco and added a tree in that.

    I need to open a aspx page(form) where user can submit the announcements. I had also written the code for that by reading from forum but its not working.

    The code for the tree is given below:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using umbraco.cms.presentation.Trees;

    using umbraco.businesslogic;

    using System.Text;

     

    namespace CustomTreeAdmin

    {

        [Tree("CustomSection", "AnnouncementTree", "Announcements")]

        public class Announcements : BaseTree

        {

            public Announcements(string application) : base(application) { }

     

            protected override void CreateRootNode(ref XmlTreeNode rootNode)

            {

                rootNode.Icon = FolderIcon;

                rootNode.OpenIcon = FolderIconOpen;

                rootNode.NodeType = "init" + TreeAlias;

                rootNode.NodeID = "init";

            }

     

            public override void RenderJS(ref StringBuilder Javascript)

            {

                Javascript.Append(

                @"

                function AnnouncementNewForm(id) {

                parent.right.document.location.href = 'Umbraco/NewAnnouncement.aspx?id=' + id;

                }");

            }

     

            public override void Render(ref XmlTree tree)

            {

                XmlTreeNode xNode = XmlTreeNode.Create(this);

                xNode.NodeID = "1";

                xNode.Text = "AnnouncementTree";

                //xNode.Icon = "subscribers.gif";

                xNode.Action = "javascript:AnnouncementNewForm("+id+")";

                tree.Add(xNode);

            }

        }   

     

    }

    I checked the console there is an error as shown below:

     

    What I am getting on the Screen:

     

    Can somebody please guide me how can i resolve this.

     

     

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 25, 2014 @ 11:22
    Jeroen Breuer
    0

    Try chaning your xNode.Action to this:

    xNode.Action = string.Format("javascript:AnnouncementNewForm('{0}');", id);

    Jeroen

  • Rahul 12 posts 83 karma points
    Mar 25, 2014 @ 12:39
    Rahul
    0

    Hi Jeroen,

    Tried by changing the xNode.Action by your code line but nothing fixed.....

    Actually Id is passing "-1" as i pasted the console request which is giving error:

    umbraco/webservices/TreeDataService.ashx?rnd=fddb45b6dbcf40c388d67674eb94c26f&id=-1&treeType=AnnouncementTree&contextMenu=true&isDialog=false&rnd2=22.3

    and the error is coming from the request is 

    Object reference not set to an instance of an object.

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 25, 2014 @ 12:42
    Jeroen Breuer
    0

    What's the id that you are trying to pass? 

    You can set the id on the rootNode.NodeID.

    For example:

    rootNode.Icon = FolderIcon;
    rootNode.OpenIcon = FolderIconOpen;
    rootNode.NodeType = "init" + TreeAlias;
    rootNode.NodeID = "1045";

    Jeroen

  • Rahul 12 posts 83 karma points
    Mar 25, 2014 @ 13:21
    Rahul
    0

    Hi Jeroen,

    I am not passing any id as you can see in my code above.

    Please guide me how would we can get the id of node if it is possible.

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 25, 2014 @ 13:45
    Jeroen Breuer
    0

    Hello,

    In your code you have the following:

    parent.right.document.location.href = 'Umbraco/NewAnnouncement.aspx?id=' + id;

    So you are passing an id to your NewAnnouncement.aspx page. Is that necessary?

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 25, 2014 @ 13:58
  • Rahul 12 posts 83 karma points
    Mar 25, 2014 @ 14:07
    Rahul
    0

    Hi Jeroen,

    No that id is not necessary.

    But is it make any change to issue please suggest....

    I already read these blogs and wrote the code with help of thses blogs.

    But issue is not resolved.

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 25, 2014 @ 14:14
    Jeroen Breuer
    0

    Try changing the following:

    @"
    function AnnouncementNewForm() {
    parent.right.document.location.href = 'Umbraco/NewAnnouncement.aspx';
    }");
    xNode.Action = "javascript:AnnouncementNewForm()";

    That way and you don't need the id.

    If that doesn't work try to figure out what the internal server error is that you get. Maybe you can find it in the logs.

    Jeroen

  • Rahul 12 posts 83 karma points
    Mar 26, 2014 @ 12:01
    Rahul
    0

    Hi Jeroen,

    By remove id its not resolve the issue.

    There is no details in the log for the same.

    I am trying to debug the source code of Umbraco by Visual studio but fails setup the source code project in visual studio.

    Is it possible to you to tell me the steps how we can setup the source code of umbraco with visual studio so we can debug the issue. 

     

  • Rahul 12 posts 83 karma points
    Mar 27, 2014 @ 12:06
    Rahul
    101

    Hi Jeroen,

    Finaly added the tree with this code:

    Mistake in upper code is that dNode.Icon = FolderIcon; is commented 

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using umbraco.cms.presentation.Trees;

    using umbraco.businesslogic;

    using System.Text;

     

    namespace CustomTreeAdmin

    {

        [Tree("announcements", "AnnouncementTree", "AboutAnnouncements")]

        public class Announcements : BaseTree

        {

            public Announcements(string application) : base(application) { }

     

            protected override void CreateRootNode(ref XmlTreeNode rootNode)

            {

                rootNode.Icon = FolderIcon;

                rootNode.OpenIcon = FolderIconOpen;

                rootNode.NodeType = "init" + TreeAlias;

                rootNode.NodeID = "init";

                

            }

     

            public override void RenderJS(ref StringBuilder Javascript)

            {

                Javascript.Append(

                     @"

                        function openAnnouncementForm(id) 

                        {

                            parent.right.document.location.href = '/Umbraco/NewAnnouncement.aspx?id=' + id;

                        }

                    ");

            }

     

            public override void Render(ref XmlTree tree)

            {           

                    

                XmlTreeNode dNode = XmlTreeNode.Create(this);

                dNode.NodeID = "1";

                dNode.Text = "Add Announcement";

                dNode.Icon = FolderIcon;

                dNode.Action = "javascript:openAnnouncementForm(" + 1 + ")";

                tree.Add(dNode);

     

     

            }

        }

     

        

    }

Please Sign in or register to post replies

Write your reply to:

Draft