Trouble with Web Treeview control
-
hi, i am having a bit fo an issue with a treeview controll that i am using on a web form. ROOT NODE CHILD CHILD NODE CHILD NODE CHILD I need the Treeview to do a PostBack only when the one of the CHILD nodes is selected, but at the moment a post back occurs at the NODE level as well. Is there any way that I could avoid the latter and only allow a post back when the CHILD node is selected??:confused: I want to execute a method on the Selected_IndexChanged event, but only when a CHILD node is selected. I dont want to postback unecessarily.. any help will be great :-) Thanks Afzal Hassen
-
hi, i am having a bit fo an issue with a treeview controll that i am using on a web form. ROOT NODE CHILD CHILD NODE CHILD NODE CHILD I need the Treeview to do a PostBack only when the one of the CHILD nodes is selected, but at the moment a post back occurs at the NODE level as well. Is there any way that I could avoid the latter and only allow a post back when the CHILD node is selected??:confused: I want to execute a method on the Selected_IndexChanged event, but only when a CHILD node is selected. I dont want to postback unecessarily.. any help will be great :-) Thanks Afzal Hassen
Hi there, To do what you want, you can create an event handler for the client side event
onselectedindexchange
of the treeview control. In the event handler, you can determine if the clicked node is a parent node or not to decide posting the page back. There are a couple of ways to check if a node is a parent or child node, for example a node is parent when its index value does not contain the delimeter.
. The sample code looks something like:function treeview_onselectedindexchange()
{
//The id of the treeview is TreeView1.
var treeView = document.getElementById("TreeView1");//Determine if the clicked node is a parent node. if(treeView.clickedNodeIndex.indexOf(".") > 0) if(event.oldTreeNodeIndex != event.newTreeNodeIndex) treeView.queueEvent('onselectedindexchange', event.oldTreeNodeIndex + ',' + event.newTreeNodeIndex);
}
Because the Treeview control also has the server side event named
onselectedindexchange
, so you can register the client side function for this event as below:function Body_Onload()
{
var treeView = document.getElementById("TreeView1");
treeView.onselectedindexchange = treeview_onselectedindexchange;
}The Body_Onload function should be called when the body element raises the
onload
event. Above is just one of a couple of available solutions. -
Hi there, To do what you want, you can create an event handler for the client side event
onselectedindexchange
of the treeview control. In the event handler, you can determine if the clicked node is a parent node or not to decide posting the page back. There are a couple of ways to check if a node is a parent or child node, for example a node is parent when its index value does not contain the delimeter.
. The sample code looks something like:function treeview_onselectedindexchange()
{
//The id of the treeview is TreeView1.
var treeView = document.getElementById("TreeView1");//Determine if the clicked node is a parent node. if(treeView.clickedNodeIndex.indexOf(".") > 0) if(event.oldTreeNodeIndex != event.newTreeNodeIndex) treeView.queueEvent('onselectedindexchange', event.oldTreeNodeIndex + ',' + event.newTreeNodeIndex);
}
Because the Treeview control also has the server side event named
onselectedindexchange
, so you can register the client side function for this event as below:function Body_Onload()
{
var treeView = document.getElementById("TreeView1");
treeView.onselectedindexchange = treeview_onselectedindexchange;
}The Body_Onload function should be called when the body element raises the
onload
event. Above is just one of a couple of available solutions.Thanks :-) do these functions get placed in the .aspx or .aspx.cs file?? forgive my ignorance i'm TOTALLY new to ASP.NET Programming :-/ Afzal "AV-E" Hassen
-
Thanks :-) do these functions get placed in the .aspx or .aspx.cs file?? forgive my ignorance i'm TOTALLY new to ASP.NET Programming :-/ Afzal "AV-E" Hassen
The aspx.cs file basically contains the code-behind of the web page, this is the server side code which only runs on the server machine. The web page .aspx can contain the static markup and server controls, server side code (inline code), client side code. The client side script basically runs at the client side not at the server side, they can be written in javascript or vbscript and they are normally placed between the open and close tags of the
script
element:<script type="text/javascript">
....
</script>In addition, they are also put in a separate file ending with .js or .vbs extensions. Because those functions are supposed to run on the client machine, so they should be placed in the
script
tag in the web page .aspx. For more information, you can see Web Forms Code Model[^] -
The aspx.cs file basically contains the code-behind of the web page, this is the server side code which only runs on the server machine. The web page .aspx can contain the static markup and server controls, server side code (inline code), client side code. The client side script basically runs at the client side not at the server side, they can be written in javascript or vbscript and they are normally placed between the open and close tags of the
script
element:<script type="text/javascript">
....
</script>In addition, they are also put in a separate file ending with .js or .vbs extensions. Because those functions are supposed to run on the client machine, so they should be placed in the
script
tag in the web page .aspx. For more information, you can see Web Forms Code Model[^]I see, Thanks for the explanation :-) it cleared up alot for me :-) thanks again.. Afzal "AV-E" Hassen
-
The aspx.cs file basically contains the code-behind of the web page, this is the server side code which only runs on the server machine. The web page .aspx can contain the static markup and server controls, server side code (inline code), client side code. The client side script basically runs at the client side not at the server side, they can be written in javascript or vbscript and they are normally placed between the open and close tags of the
script
element:<script type="text/javascript">
....
</script>In addition, they are also put in a separate file ending with .js or .vbs extensions. Because those functions are supposed to run on the client machine, so they should be placed in the
script
tag in the web page .aspx. For more information, you can see Web Forms Code Model[^]hi, is the same possible with the ASP 2.0 treeview control?? the .queueEvent(....) is not supported by the control, so how might i be able to work around this?? Afzal "AV-E" Hassen
-
hi, is the same possible with the ASP 2.0 treeview control?? the .queueEvent(....) is not supported by the control, so how might i be able to work around this?? Afzal "AV-E" Hassen
With the TreeView control in the ASP.NET 2.0, things become much easier for you thanks to a technique called the Client Callback. You can take a look at the tutorial below: http://beta.asp.net/QuickStartv20/aspnet/doc/ctrlref/navigation/treeview.aspx[^]
-
With the TreeView control in the ASP.NET 2.0, things become much easier for you thanks to a technique called the Client Callback. You can take a look at the tutorial below: http://beta.asp.net/QuickStartv20/aspnet/doc/ctrlref/navigation/treeview.aspx[^]
Thanks again, i had a look at that link and it turns out, all i really needed to was set the
SelectAction
property of the node that i didnt want to post back toSelectedAction.Expand
and hey Presto! the treeview works exactly like i needed it to.. thanks minhpc_bk :-D you've been a great help man! Afzal "AV-E" Hassen -
Thanks again, i had a look at that link and it turns out, all i really needed to was set the
SelectAction
property of the node that i didnt want to post back toSelectedAction.Expand
and hey Presto! the treeview works exactly like i needed it to.. thanks minhpc_bk :-D you've been a great help man! Afzal "AV-E" HassenYes, you're right. With the ASP.NET 2.0 treeview control, you only need to do few things to make it work in the way you want. And the treeview control is just one of examples of using the client callback. The callback can help the web developer easily communicate with the server side without reloading the entire web page. Its behaviour is similar to some AJAX (one of the most concerned buzzword recently) libraries out there for example AJAX.NET. You can learn more about the client callback from the blog entries of a Microsoft developer: http://weblogs.asp.net/bleroy/archive/2005/04/08/397761.aspx[^] Have fun with client callback! :-D