Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Trouble with Web Treeview control

Trouble with Web Treeview control

Scheduled Pinned Locked Moved ASP.NET
helpquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AfzalHassen
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • A AfzalHassen

      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

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • M minhpc_bk

        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.

        A Offline
        A Offline
        AfzalHassen
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • A AfzalHassen

          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

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          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[^]

          A 2 Replies Last reply
          0
          • M minhpc_bk

            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[^]

            A Offline
            A Offline
            AfzalHassen
            wrote on last edited by
            #5

            I see, Thanks for the explanation :-) it cleared up alot for me :-) thanks again.. Afzal "AV-E" Hassen

            1 Reply Last reply
            0
            • M minhpc_bk

              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[^]

              A Offline
              A Offline
              AfzalHassen
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • A AfzalHassen

                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

                M Offline
                M Offline
                minhpc_bk
                wrote on last edited by
                #7

                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[^]

                A 1 Reply Last reply
                0
                • M minhpc_bk

                  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[^]

                  A Offline
                  A Offline
                  AfzalHassen
                  wrote on last edited by
                  #8

                  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 to SelectedAction.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

                  M 1 Reply Last reply
                  0
                  • A AfzalHassen

                    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 to SelectedAction.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

                    M Offline
                    M Offline
                    minhpc_bk
                    wrote on last edited by
                    #9

                    Yes, 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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups