TreeView OnSelectedIndexChange Client Side Event Question

Last post 09-29-2003 6:57 PM by seljo. 6 replies.

Sort Posts:

  • TreeView OnSelectedIndexChange Client Side Event Question

    04-17-2003, 4:31 PM
    • Participant
      1,530 point Participant
    • MLibby
    • Member since 06-21-2002, 2:40 PM
    • Virginia
    • Posts 306
    Hello everyone,

    I'm able to successfully handle the OnSelectedIndexChange client side event but now how do I get to the text and data of the selected item using the index?

    Here is my code:

    WebForm1.aspx.cs
    ...
    TreeXmlSql.Attributes.Add("onselectedindexchange", "myFunction();");
    ...

    WebForm1.aspx
    ...
    <!--
    function myFunction()
    {
    var oldIndex= window.event.oldTreeNodeIndex;
    var newIndex= window.event.newTreeNodeIndex;
    alert("The value of the oldTreeNodeIndex property is " + oldIndex +
    "\nThe value of the newTreeNodeIndex property is " + newIndex);
    }
    //-->
    ...

    Any help is greatly appeciated,
    Mike
    - Cache entire web sites at the client and server and keep cache current. Cache just got easier!
  • Re: TreeView OnSelectedIndexChange Client Side Event Question

    04-21-2003, 11:25 AM
    • Member
      30 point Member
    • kevin_jones
    • Member since 04-01-2003, 3:59 PM
    • Posts 6
    var Node = MyTree.getTreeNode(Index);
    var NodeType = FromNode.getAttribute("type");
    var NodeName = FromNode.getAttribute("text");
    window.status = "The type is " + Type + " and the name is " + Name + ".";
  • Re: TreeView OnSelectedIndexChange Client Side Event Question

    05-04-2003, 9:16 PM
    • Member
      5 point Member
    • molingw
    • Member since 05-03-2003, 10:16 PM
    • Posts 1
    hello! i met the same question. i do not how to get the Event when i click the node. because i want to display then node's text which i click.

    thank you!

  • Re: TreeView OnSelectedIndexChange Client Side Event Question

    05-05-2003, 11:26 AM
    • Participant
      1,530 point Participant
    • MLibby
    • Member since 06-21-2002, 2:40 PM
    • Virginia
    • Posts 306
    Here's the scoop...
    Unlike the HTML server controls, for the Web server controls, you cannot simply use the HTML sytax to add cliend-side event handling. The reason is ASP.NET already uses client-side event handling code to perform automatic postback operations. So for Web controls you have to use Attributes.Add(...) to handle the client side click. Here are code snippets...

    <HTML>
    <HEAD>
    <title>Main</title>
    ...
    <script language="javascript">
    <!--
    function myFunction()
    {
    var newIndex= window.event.newTreeNodeIndex;
    var Node = MyTree.getTreeNode(newIndex);
    var NodeName = Node.getAttribute("text");
    // I'm using an html text box here because I don't
    // know how to set the web form text box in a client
    // java script. Any help would be appreciated.
    document.Main.htbSelected.value = NodeName;
    }
    //-->
    </script>
    </HEAD>
    ...

    C# code:
    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    // I'm using one of many ways to populate the tree, an xml file.
    MyTree.TreeNodeSrcFile = MapPath("EmpReportsTo.tns.xml");
    MyTree.Attributes.Add("onselectedindexchange", "myFunction();");
    DataBind();
    }
    }
    ...

    That should be all you need. Let me know if this helps,
    Mike


    - Cache entire web sites at the client and server and keep cache current. Cache just got easier!
  • Re: TreeView OnSelectedIndexChange Client Side Event Question

    05-21-2003, 6:04 AM
    • Member
      5 point Member
    • majstor
    • Member since 05-21-2003, 5:55 AM
    • Posts 1
    It helps and works fine with IE 6.0 but on IE 5.0 window.event.newTreeNodeIndex is undefined and on line
    newIndex= window.event.newTreeNodeIndex;
    reports an error: "object doesn't support property or method"

    Any idea?
  • Re: TreeView OnSelectedIndexChange Client Side Event Question

    05-21-2003, 2:16 PM
    • Member
      5 point Member
    • luvnsv
    • Member since 05-19-2003, 5:22 AM
    • Posts 1
    i also have the same problem getting the text that i clicked on the tree
    any idea on how to do?
    i'm using vb, can help out?

    thanks...
  • Re: TreeView OnSelectedIndexChange Client Side Event Question

    09-29-2003, 6:55 PM
    • Member
      5 point Member
    • seljo
    • Member since 09-29-2003, 2:09 PM
    • Posts 1
    I am having trouble capturing any client side events for this control. Could you post the entire .aspx HTML source for me to compare to mine? I am trying to add nodes dynamically from a DB. I can do this by setting AutoPostback to true, but everytime a click event occurs, the page gets posted back. This is unacceptable! I need to be able to determine in client side script when the page posts back. Any ideas would be greatly appreciated. Here is my aspx HTML code:


    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="treeview.aspx.vb" Inherits="ilh.WebForm1"%>
    <%@ Register TagPrefix="ie" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
    <%@ import namespace="Microsoft.Web.UI.WebControls"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>ILH Browser</title>
    <script language="javascript">
    <!--
    function js_indexChanged()
    {
    document.write("hello");
    }
    -->
    </script>

    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">

    <asp:button id="Button1" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 64px" runat="server"
    Text="Refresh" Width="65px" Height="24px"></asp:button>

    <ie:treeview id="Treeview1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 104px"
    runat="server" Expanded="false" Autopostback="false" NAME="Treeview1"></ie:treeview>

    <asp:label id="lblNodeCount" style="Z-INDEX: 103; LEFT: 104px; POSITION: absolute; TOP: 64px"
    runat="server" Width="320px" Height="16px">Number of nodes</asp:label>

    </form>
    </body>
    </HTML>

    my vb code:

    ...

    sub page_load()
    ...
    treeview1.atributes.add("onselectedindexchange","js_indexChanged();")
    ...
    end sub
Page 1 of 1 (7 items)