This is a migrated thread and some comments may be shown as answers.

ServerSideCallBack and RegisterStartupScript

2 Answers 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Dominic Feron
Top achievements
Rank 1
Dominic Feron asked on 18 Sep 2009, 12:52 PM
Hi all,

I have a radTreeView that generates itself on the page load event. Then, when the NodeExpand event is triggered, the node's child are added dynamically to the parent node. From there, everything works well.

Also, just after the page load event, a javascript method is called to add a click event on each icon of the tree. Here how I do this (I picked up the code from another thread in this forum) :

<script type="text/javascript"
 
      //This function must not be between tags with runat="server" 
      //It adds the click event to every icon in the tree 
      function pageLoad() { 
         
        var tree = $find("<%=oTreeUsers.ClientID %>"); 
        var i;       
        for (i = 0; i < tree.get_allNodes().length; i++) { 
          var value = tree.get_allNodes()[i].get_value(); 
          var imageElement = tree.get_allNodes()[i].get_imageElement(); 
          var textElement = tree.get_allNodes()[i].get_textElement(); 
 
          imageElement.id = tree.get_allNodes()[i].get_value(); 
          textElement.id = tree.get_allNodes()[i].get_value(); 
           
          if (imageElement.addEventListener) { 
            //FireFox 
            imageElement.onclick = function(e) { clickHandler(this, e); }; 
            imageElement.oncontextmenu = function(e) { clickHandler(this, e); }; 
            textElement.oncontextmenu = function(e) { clickHandler(this, e); }; 
          } 
          else { 
            //IE 
            imageElement.onclick = function() { clickHandler(this, window.event); }; 
            imageElement.oncontextmenu = function() { clickHandler(this, window.event); return false; }; 
            textElement.oncontextmenu = function() { clickHandler(this, window.event); return false; }; 
          } 
        } 
 
        function clickHandler(imageElement, e) { 
          ShowRadMenu(imageElement.id, e); 
        } 
 
 
      }       
  </script>  

When a user expand a node and all the sub nodes are created with the property oChildLeaf.ExpandMode = TreeNodeExpandMode.ServerSide, everything works well because the javascript method catch the new created nodes. The click event is then added to the icon of the nodes.

But when I set the oChildLeaf.ExpandMode = TreeNodeExpandMode.ServerSideCallBack to the created nodes, the javascript won't catch the new nodes because only a partial postback is sent to the server.

My problem is that I need to set the nodes of my tree to ServerSideCallBack for optimizing performance but the javascript click event won't follow. I tried using the ScriptManager.RegisterStartupScript method to call my javascript on the NodeExpand server-side event but it doesn't seem to work.

Can anyone help me on this?

 

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Sep 2009, 01:27 PM
Hello Dominic Feron,

Indeed the pageLoad function is executed only after postback or ASP.NET Ajax request. As you have observed it is not executed when RadTreeView is performing a callback. As a workaround I can suggest using the OnClientNodePopulated event which fires when the nodes are loaded on demand using ServerSideCallback mode.

Regards,
Albert,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Dominic Feron
Top achievements
Rank 1
answered on 18 Sep 2009, 01:40 PM
God it's good to see this working.

Thanks a lot!
Tags
TreeView
Asked by
Dominic Feron
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Dominic Feron
Top achievements
Rank 1
Share this question
or