asp.net 2.0 treeview is slow

  • Thread starter Thread starter Billy Zhang
  • Start date Start date
B

Billy Zhang

Now we have to load the whole company's organizational relationships into one
TreeView which has at lest 6~7 layer and including 300~400 nodes.In every
node,there is a checkbox.

So we need following cascade selected effect:

1. Every time we select one node,all his child nodes' state will be changed
into selected automatically(if this node has child node).

2 . Every time we select one node,his father nodes' state will be be changed
into selected automatically.

Now we load all these nodes into TreeView in PageLoad event.And implement
the cascade selected effect above by using TreeNodeCheckChanged event.In the
TreeNodeCheckChanged event,we will be able to find the selected node,and then
we can find his father node and son nodes to change their state.

But now we find out that because of the number of the nodes is so big that
the treeview is very slow to loaded all the nodes.

How to speed the treeview performance?

Thanks,
-Billy Zhang

How can we promote this TreeView's performance.
 
Good afternoon, Mr. Zhang. Welcome to Microsoft Newsgroup Support Service!
My name is Jialiang Ge [MSFT]. I will help you with this issue.

According to the description, you register the "TreeNodeCheckChanged" event
for asp:TreeView control, and implement the effect of cascaded selection in
the server-side code. For each change of the checked state, a page
postback will happen to run the TreeNodeCheckChanged event handler, and
reload the 300~400 nodes into the treeview. This process, as you have
noticed, consumes a lot of performance. In order to improve the
performance, we may considering running the "cascaded selection" logic on
the client side. In this way, no postback or reload will happen, and it can
bring a very smooth use experience to our users.

In order to well demonstrate the client-side scripts for your feature
requests, I have built a sample website. You can download it with Outlook
Express or Windows Mail.

The keys in the sample project are as follows:

1. we have the registration of a client-side event "onclick" in
asp:TreeView control:
<asp:TreeView ID="TreeView1" runat="server" onclick="CheckEvent()"
DataSourceID="SiteMapDataSource1" ShowCheckBoxes="All">
When a checkbox is selected, it will trigger the javascript function
"CheckEvent" running on client-side.

2. Main javascript functions:
function public_GetParentByTagName(element, tagName)
{
var parent = element.parentNode;
var upperTagName = tagName.toUpperCase();

while (parent && (parent.tagName.toUpperCase() != upperTagName))
{
parent = parent.parentNode ? parent.parentNode :
parent.parentElement;
}
return parent;
}
// set the parent node to be checked
function setParentChecked(objNode)
{
var objParentDiv = public_GetParentByTagName(objNode,"div");
if(objParentDiv==null || objParentDiv == "undefined")
{
return;
}
var objID = objParentDiv.getAttribute("ID");
objID = objID.substring(0,objID.indexOf("Nodes"));
objID = objID+"CheckBox";
var objParentCheckBox = document.getElementById(objID);
if(objParentCheckBox==null || objParentCheckBox == "undefined")
{
return;
}
if(objParentCheckBox.tagName!="INPUT" && objParentCheckBox.type ==
"checkbox")
return;
objParentCheckBox.checked = true;
setParentChecked(objParentCheckBox);
}
// set the children to be unchecked.
function setChildUnChecked(divID)
{
var objchild = divID.children;
var count = objchild.length;
for(var i=0;i<objchild.length;i++)
{
var tempObj = objchild;
if(tempObj.tagName=="INPUT" && tempObj.type == "checkbox")
{
tempObj.checked = false;
}
setChildUnChecked(tempObj);
}
}
// set the children to be checked
function setChildChecked(divID)
{
var objchild = divID.children;
var count = objchild.length;
for(var i=0;i<objchild.length;i++)
{
var tempObj = objchild;
if(tempObj.tagName=="INPUT" && tempObj.type == "checkbox")
{
tempObj.checked = true;
}
setChildChecked(tempObj);
}
}
// trigger the event
function CheckEvent()
{
var objNode = event.srcElement;
if(objNode.tagName!="INPUT" || objNode.type!="checkbox")
return;
if(objNode.checked==true)
{
setParentChecked(objNode);
var objID = objNode.getAttribute("ID");
var objID = objID.substring(0,objID.indexOf("CheckBox"));
var objParentDiv = document.getElementById(objID+"Nodes");
if(objParentDiv==null || objParentDiv == "undefined")
{
return;
}
setChildChecked(objParentDiv);
}
else
{
var objID = objNode.getAttribute("ID");
var objID = objID.substring(0,objID.indexOf("CheckBox"));
var objParentDiv = document.getElementById(objID+"Nodes");
if(objParentDiv==null || objParentDiv == "undefined")
{
return;
}
setChildUnChecked(objParentDiv);
}
}

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thank you, you can close this.

Jialiang Ge said:
Good afternoon, Mr. Zhang. Welcome to Microsoft Newsgroup Support Service!
My name is Jialiang Ge [MSFT]. I will help you with this issue.

According to the description, you register the "TreeNodeCheckChanged" event
for asp:TreeView control, and implement the effect of cascaded selection in
the server-side code. For each change of the checked state, a page
postback will happen to run the TreeNodeCheckChanged event handler, and
reload the 300~400 nodes into the treeview. This process, as you have
noticed, consumes a lot of performance. In order to improve the
performance, we may considering running the "cascaded selection" logic on
the client side. In this way, no postback or reload will happen, and it can
bring a very smooth use experience to our users.

In order to well demonstrate the client-side scripts for your feature
requests, I have built a sample website. You can download it with Outlook
Express or Windows Mail.

The keys in the sample project are as follows:

1. we have the registration of a client-side event "onclick" in
asp:TreeView control:
<asp:TreeView ID="TreeView1" runat="server" onclick="CheckEvent()"
DataSourceID="SiteMapDataSource1" ShowCheckBoxes="All">
When a checkbox is selected, it will trigger the javascript function
"CheckEvent" running on client-side.

2. Main javascript functions:
function public_GetParentByTagName(element, tagName)
{
var parent = element.parentNode;
var upperTagName = tagName.toUpperCase();

while (parent && (parent.tagName.toUpperCase() != upperTagName))
{
parent = parent.parentNode ? parent.parentNode :
parent.parentElement;
}
return parent;
}
// set the parent node to be checked
function setParentChecked(objNode)
{
var objParentDiv = public_GetParentByTagName(objNode,"div");
if(objParentDiv==null || objParentDiv == "undefined")
{
return;
}
var objID = objParentDiv.getAttribute("ID");
objID = objID.substring(0,objID.indexOf("Nodes"));
objID = objID+"CheckBox";
var objParentCheckBox = document.getElementById(objID);
if(objParentCheckBox==null || objParentCheckBox == "undefined")
{
return;
}
if(objParentCheckBox.tagName!="INPUT" && objParentCheckBox.type ==
"checkbox")
return;
objParentCheckBox.checked = true;
setParentChecked(objParentCheckBox);
}
// set the children to be unchecked.
function setChildUnChecked(divID)
{
var objchild = divID.children;
var count = objchild.length;
for(var i=0;i<objchild.length;i++)
{
var tempObj = objchild;
if(tempObj.tagName=="INPUT" && tempObj.type == "checkbox")
{
tempObj.checked = false;
}
setChildUnChecked(tempObj);
}
}
// set the children to be checked
function setChildChecked(divID)
{
var objchild = divID.children;
var count = objchild.length;
for(var i=0;i<objchild.length;i++)
{
var tempObj = objchild;
if(tempObj.tagName=="INPUT" && tempObj.type == "checkbox")
{
tempObj.checked = true;
}
setChildChecked(tempObj);
}
}
// trigger the event
function CheckEvent()
{
var objNode = event.srcElement;
if(objNode.tagName!="INPUT" || objNode.type!="checkbox")
return;
if(objNode.checked==true)
{
setParentChecked(objNode);
var objID = objNode.getAttribute("ID");
var objID = objID.substring(0,objID.indexOf("CheckBox"));
var objParentDiv = document.getElementById(objID+"Nodes");
if(objParentDiv==null || objParentDiv == "undefined")
{
return;
}
setChildChecked(objParentDiv);
}
else
{
var objID = objNode.getAttribute("ID");
var objID = objID.substring(0,objID.indexOf("CheckBox"));
var objParentDiv = document.getElementById(objID+"Nodes");
if(objParentDiv==null || objParentDiv == "undefined")
{
return;
}
setChildUnChecked(objParentDiv);
}
}

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights
 
You are welcome. I'm glad to help you.

If you have any other questions, please don't hesitate to let me know.

Have a great day!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Back
Top