Dynamic TreeView XML Error in C#

Posted on 2005-04-12
Last Modified: 2008-01-09
I'm using the standard TreeView control in an aspx page. I'm trying to load the contents of the tree from an xml file. This works fine when I use a static xml file (test.xml):

<iews:TreeView runat="server" AutoPostBack="true" ID="Treeview1">
<iews:treenode Text="test.xml" TreeNodeSrc="/Controls/test.xml" >

Unfortunately, I need to create the xml dynamically, so I'm trying to generate it with an aspx page (test.aspx), and load it like this:

<iews:TreeView runat="server" AutoPostBack="true" ID="Treeview1">
<iews:treenode Text="test.xml" TreeNodeSrc="/Controls/test.aspx" >

When I use test.aspx, I get an error:

"System.Exception: The XML loaded from TreeNodeSrc=http://localhost/SkyArc/Players/Controls/test.aspx, TreeNodeXslSrc= did not contain the required outer <TREENODES> container."

I have copied the output from test.aspx into test.xml, so if I point my browser directly at each file, their source looks IDENTICAL:

<?xml version="1.0" encoding="utf-8" ?>
      <treenode Text="363 Market" CHECKBOX="true" ></treenode>
      <treenode Text="363 Market" CHECKBOX="true" ></treenode>
      <treenode Text="Ohio" CHECKBOX="true" ></treenode>

One more thing: I've loaded test.aspx into the TreeView sample project and pointed the tree at it in the same way. It worked fine. I feel like I'm taking crazy pills! Why should my other project be any different?

Is this a Page.Response.ContentType kind of issue? I've looked all over the internet for this error, and have found discussions about it in many places... and it's never actually solved. Any thoughts?

Question by:juicemonger
    LVL 25

    Expert Comment

    Try the following for the aspx XML page:

    Page.Response.ContentType = "application/xml"

    HTH, Nauman.

    Author Comment

       I had tried setting ContentType to "text/xml", but neither that nor your suggestion made any difference.

    I've noticed something new: I expect test.aspx to be generated when I expand the parent node. In fact, I placed a breakpoint in the codebehind Page_Load() and found that it is never reached when I expand the parent node. I see the error page before Page_Load is called. Of course, if I point the browser directly at test.aspx, Page_Load() is called (and broken) immediately.

    Author Comment

    Is it possible that it's a permissions issue? My web app requires a username and password. If I am not logged in, I cannot point my browser directly at test.aspx -- I am redirected to the login page. The error page I've been seeing indicates that I'm seeing a server issue, not a browser issue - is it possible that the server is looking for the page from a port (or something) that is not logged into the system and is thus not granted proper access?

    Author Comment

    Wooooooooooooooo! Solved it. After 3 days.

    When the TreeView Control requested test.aspx, it was doing so without authorization, so it was being redirected to the login page. I added:

      <location path="test.aspx">
            <allow users="?" />
    <configuration> Web.config and everything worked.

    So... tell me a joke and... win 500 points?

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now