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.
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.
Try chaning your xNode.Action to this:
Jeroen
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.
What's the id that you are trying to pass?
You can set the id on the rootNode.NodeID.
For example:
Jeroen
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.
Hello,
In your code you have the following:
So you are passing an id to your NewAnnouncement.aspx page. Is that necessary?
Jeroen
Maybe these blog posts can also help:
http://www.geckonewmedia.com/blog/2009/08/03/how-to-create-a-custom-section-in-umbraco-4/
http://adaodeveloper.blogspot.nl/2013/01/create-new-custom-section-in-umbraco-48.html
http://www.it-potato.com/2013/07/adding-a-custom-section-in-umbraco-6/
http://www.theoutfield.net/blog/2012/07/creating-custom-applications-and-trees-in-umbraco-48plus
Jeroen
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.
Try changing the following:
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
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.
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);
}
}
}
is working on a reply...