I'm attempting to create a custom web part that will display information using a TreeView. I'm able to retrieve the required information without any problems as I can render it in raw text. When I attempt to use a TreeView I can render the control, but I'm not able to expand any of the nodes (or collapse them if I make them expanded by default) instead I get an error message stating that "Problem with this Web page might prevent t from being displayed properly or functioning properly." The details of the error are as follows:
Line: 1
Char: 1
Error: Object Expected
Code: 0
Url: The url of the page I'm viewing
I've reduced the Web Part to just creating a simple TreeView and rendering it, my code is as follows:
|
public class MyTreeView : System.Web.UI.WebControls.WebParts.WebPart
{ protected override void Render(HtmlTextWriter writer) { SPTreeView t = new SPTreeView(); this.Controls.Add(t);
t.Nodes.Add(new System.Web.UI.WebControls.TreeNode("Top 1"));
t.Nodes[0].ChildNodes.Add(new System.Web.UI.WebControls.TreeNode("Sub 1")); t.Nodes[0].ChildNodes.Add(new System.Web.UI.WebControls.TreeNode("Sub 2")); t.RenderControl(writer);
} } I've also tried using the normal TreeView class from System.Web.UI.WebControls with the same result. |
I'm hoping someone can point out to me what I'm missing, thanks!

Error with TreeView in Web Part
mstep100
I too had the same problem . Thing is js expecting some object . real y i don't know which object it's requesting. But wt i did is I have created and rendered one more TreeView ASP.NET control which ll provide that object. My Code is
here tv is no use other than providing that Java script Object ( which is in the js error message )
Button btnSave; SPTreeView sptv; // Our Display control TreeView tv; // Dummy TreeNode treenode; TreeNode tn; SPList list; SPWeb _web;
protected override void CreateChildControls(){
base.CreateChildControls();tv =
new TreeView(); // Dummy Tree view asp.net controlControls.Add(tv);
sptv =
new SPTreeView(); // Our Tree view to displaybtnSave =
new Button();btnSave.Text =
"Save" ;btnSave.Click +=
new EventHandler(btnSave_click);Controls.Add(btnSave);
}
protected override void Render(HtmlTextWriter writer){
GetTreeView(); // Function to Fill all Nodes in to the SPTreeView control
Controls.Add(sptv); // Adding to the page
sptv.RenderControl(writer); // Rendering
tv.RenderControl(writer); // Dummy asp.net control
writer.Write(
"<br><br>");btnSave.RenderControl(writer);
}
This code is working for me...
Chees
Moorthy .A
India.
Fiddel
Andrei Faber
t.ID = "MyTree1";
t.SkipLinkText = "";
M. Nicholas
I'm currently experiencing the same problem. If anyone has any fix for this, I'd be extremely grateful.
// Eric
ScaryKidsScaringKids
Rahul Singla
Hello McGuire,
I am facing an error "Object expected" which sounds similar to your issue. Here is what i am trying to do:
- Add the treeview control in RenderControl method.
- Build the treeview in CreateChildControls method
However, clicking any of the nodes in the treeview does result in this javascript error.
Is there any other way of resolving the issue
Thanks in advance,
Regards,
Siku