Microsoft TreeView DataBind Performance Problems

A

Aidan Marcuss

I am seeing significant performance problems with the TreeView (from
the Microsoft.Web.UI.WebControls namespace) when trying to data bind it
on the server side. I set the TreeNodeSrc property and the
TreeNodeTypeSrc property and then call the DataBind() method. I am
setting each of these properties to a string of XML.

As the payload grows, this becomes terribly slow. This is all server
side.

I've found that this may have to do with the way the control interprets
the values of the TreeNodeSrc & TreeNodeTypeSrc properties. According
to the documentation, these properties can be set to one of three
values: "A value that indicates the URL of an XML file, System.String,
or XML data island containing TreeNode elements.". It would appear that
they way the DataBind method interrupts these values is by first
attempting to data bind to the results of a web request to a URL equal
to the value of the property. It would then appear to try and interpret
it is a string of XML. This doesn't make much sense, because, the
string of XML can be very long and it has to send out a very long web
request to try and data bind to. If you look at your web log, you'll
see requests like:

21:44:15 127.0.0.1 GET /< 404

This call obviously fails. It would appear to then properly treat it as
a string. I believe these requests (one for TreeNodeTypeSrc &
TreeNodeSrc) play a significant part in the slow down.
Does anyone have any idea about how to control this behavior?
 
P

Patrick Olurotimi Ige

Aida..
I have used treeview in a coule of projects..
Binding with XML was quite cool and fast enough..from Database was quite
slow..!
U have to remember that it musn't have more than 1000 nodes (as stated
from the TreeView Web ref site)
Enjoy
Patrick
 
A

aidan.s.marcuss

Just to be clear - I'm not dealing with a situation where I've got more
than 1000 nodes. This has much more to do with the way the server side
control databinds then anything else - at least that is my working
hypothesis.

I'm trying to work around this by sending the XML to the client-side
and databinding there, using the code in the HTC. This works for the
most part execpt the HTC's databind method doesn't appear to properly
account for the EXPANDABLE="Always" attribute on TreeNodeTypes when
those types are at the root.
 
A

aidan.s.marcuss

I've done some more investigation, using Lutz Roeder's indispensible
..NET Reflector (http://www.aisto.com/roeder/dotnet/) and my fear has
been confirmed: the data binding code assumes the TreeNodeSrc and
TreeNodeTypeSrc are URIs and first trying to bind to them that way.
What's worse is that it uses a try...catch paradigm to find out they
aren't.

ReadXmlSrc is called, indirectly, by DataBind to perform the actual
data binding.

internal TreeView ReadXmlSrc(string TreeNodeSrc, string
TreeNodeXsltSrc, string strOuter)
{
bool flag1 = false;
if (TreeNodeSrc != string.Empty)
{
XmlTextReader reader1;
try
{
reader1 = this.GetXmlReaderFromUri(TreeNodeSrc,
TreeNodeXsltSrc);
flag1 = reader1.Read();
}
catch
{
reader1 = this.GetXmlReaderFromString(TreeNodeSrc,
TreeNodeXsltSrc);
if (reader1 != null)
{
flag1 = reader1.Read();
}
}
if ((reader1 != null) && flag1)
{
if (!reader1.IsStartElement(strOuter))
{
throw new
Exception(string.Format(Util.GetStringResource("TreeMissingOuterContainer"),
TreeNodeSrc, TreeNodeXsltSrc));
}
string text1 = reader1.ReadInnerXml();
string[] textArray1 = new string[5] { "<%@ Register
TagPrefix='_TreeViewPrefix' Assembly='",
typeof(TreeView).Assembly.ToString(), "'
Namespace='Microsoft.Web.UI.WebControls' %><%@ import
Namespace='Microsoft.Web.UI.WebControls' %><_TreeViewPrefix:TREEVIEW
runat='server'>", text1, "</_TreeViewPrefix:TREEVIEW>" } ;
text1 = string.Concat(textArray1);
Control control1 = this.Page.ParseControl(text1);
return (TreeView) control1.Controls[0];
}
}
return null;
}
 
A

aidan.s.marcuss

I've done some more investigation, using Lutz Roeder's indispensible
..NET Reflector (http://www.aisto.com/roeder/dotnet/) and my fear has
been confirmed: the data binding code assumes the TreeNodeSrc and
TreeNodeTypeSrc are URIs and first trying to bind to them that way.
What's worse is that it uses a try...catch paradigm to find out they
aren't.

ReadXmlSrc is called, indirectly, by DataBind to perform the actual
data binding.

internal TreeView ReadXmlSrc(string TreeNodeSrc, string
TreeNodeXsltSrc, string strOuter)
{
bool flag1 = false;
if (TreeNodeSrc != string.Empty)
{
XmlTextReader reader1;
try
{
reader1 = this.GetXmlReaderFromUri(TreeNodeSrc,
TreeNodeXsltSrc);
flag1 = reader1.Read();
}
catch
{
reader1 = this.GetXmlReaderFromString(TreeNodeSrc,
TreeNodeXsltSrc);
if (reader1 != null)
{
flag1 = reader1.Read();
}
}
if ((reader1 != null) && flag1)
{
if (!reader1.IsStartElement(strOuter))
{
throw new
Exception(string.Format(Util.GetStringResource("TreeMissingOuterContainer"),
TreeNodeSrc, TreeNodeXsltSrc));
}
string text1 = reader1.ReadInnerXml();
string[] textArray1 = new string[5] { "<%@ Register
TagPrefix='_TreeViewPrefix' Assembly='",
typeof(TreeView).Assembly.ToString(), "'
Namespace='Microsoft.Web.UI.WebControls' %><%@ import
Namespace='Microsoft.Web.UI.WebControls' %><_TreeViewPrefix:TREEVIEW
runat='server'>", text1, "</_TreeViewPrefix:TREEVIEW>" } ;
text1 = string.Concat(textArray1);
Control control1 = this.Page.ParseControl(text1);
return (TreeView) control1.Controls[0];
}
}
return null;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top