ServerSideCallBack and RegisterStartupScript

3 posts, 0 answers
  1. Dominic Feron
    Dominic Feron avatar
    4 posts
    Member since:
    Aug 2009

    Posted 18 Sep 2009 Link to this post

    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(); 
     = tree.get_allNodes()[i].get_value(); 
     = tree.get_allNodes()[i].get_value(); 
              if (imageElement.addEventListener) { 
                imageElement.onclick = function(e) { clickHandler(this, e); }; 
                imageElement.oncontextmenu = function(e) { clickHandler(this, e); }; 
                textElement.oncontextmenu = function(e) { clickHandler(this, e); }; 
              else { 
                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(, e); 

    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. Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 18 Sep 2009 Link to this post

    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.

    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.
  3. Dominic Feron
    Dominic Feron avatar
    4 posts
    Member since:
    Aug 2009

    Posted 18 Sep 2009 Link to this post

    God it's good to see this working.

    Thanks a lot!
Back to Top