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