Link to home
Start Free TrialLog in
Avatar of juicemonger
juicemongerFlag for United States of America

asked on

Dynamic TreeView XML Error in C#

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" >
</iews:treenode>
</iews:TreeView>

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" >
</iews:treenode>
</iews:TreeView>

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" ?>
<TREENODES>
      <treenode Text="363 Market" CHECKBOX="true" ></treenode>
      <treenode Text="363 Market" CHECKBOX="true" ></treenode>
      <treenode Text="Ohio" CHECKBOX="true" ></treenode>
</TREENODES>

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?

Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

Try the following for the aspx XML page:

Page.Response.ContentType = "application/xml"

HTH, Nauman.
Avatar of juicemonger

ASKER

Nauman,
   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.
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?
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:

<configuration>
  <location path="test.aspx">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>
  </location>
<configuration>

...to Web.config and everything worked.

So... tell me a joke and... win 500 points?
ASKER CERTIFIED SOLUTION
Avatar of PAQ_Man
PAQ_Man
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial