Hi Victor,
As for the ASP.NET 2.0 Treeview, it is a new control which targeting
multiple web browsers unlike the original IE WebControl TreeView.
Therefore, it may lack many client-side rich behaviors like the IE
webcontrol TreeView.
Currently, for the ASP.NET 2.0 TreeView, we can not add client-side scritp
handler for individual TreeNode(the treenode is not a child control, but a
normal class). What we can do is add a client-side handler for the TreeView
control. e.g.
==================
<asp:TreeView ID="TreeView1" runat="server"
oncontextmenu="javascript
:treeview_oncontextmenu() ;return false;" >
or
protected void Page_Load(object sender, EventArgs e)
{
TreeView1.Attributes["oncontextmenu"]="javascript
:treeview_oncontextmenu();r
eturn false;";
}
===================
Then, this event will be triggered when you right click on any part of the
TreeView(the same for any other client events like "onclick" .....). If you
want to trigger the exact individual TreeNode which trigger the event, we
need to add some additional script code to detect whether the event is
raised by a TreeNode(each treenode by default is rendered as an html link
<ain the page's output). here is a test script function which detect
which TreeNode is right clicked and display its "internal id" and
"TreeNodeName":
=========================
<script language="javascript">
function treeview_oncontextmenu()
{
var obj = window.event.srcElement;
if(obj.tagName == "A")
{
alert("id: " + obj.id + ", name: " + obj.innerHTML);
}
}
</script>
========================
I get this idea from the following article, I think it will be helpful to
you:
#ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript
http://harishmvp.blogspot.com/2006/0...boxes-check.ht
ml
BTW, due to the limitation of the current implementation of ASP.NET
TreeView control, we could only get the TreeNode's id or name information,
but can not manipulate it like server-side code.
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.