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

Client Side Expand method not firing server callback

6 Answers 178 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 21 Sep 2011, 11:23 PM
Hi,

I have a TreeView where all the nodes expand mode is set to ServerSideCallback. When new nodes are added their expand mode is also set to ServerSideCallback.

In my situation I need to expand the selected node based on the result of a partial postback.

On the server side I have a handler for the NodeExpand event.

protected void rtvMain_NodeExpand(object sender, RadTreeNodeEventArgs e)
{
    // Logic/Breakpoint here

}



And I have a javascript function that looks like this:

 function ExpandSelectedNode() {
                 var tree = $find("<%= rtvMain.ClientID %>");

                 if (tree.get_selectedNode() != null) {

                     var selectedNode = tree.get_selectedNode();
                     selectedNode.expand();
                 }
             }


After the ajax/partial postback I call the javascript function by registering a startup script. I use ScriptManager.RegisterStartupScript and call my javascript function "ExpandSelectedNode()"

In the treeview I see the default loading animation appear on the selected node, which would indicated it is performing an asynchronous operation. The problem is that the server side handler "rtvMain_NodeExpand()" never gets called.


However, when I click the [+] next to the treeview item the postback is fired and it calls "rtvMain_NodeExpand()" as it should. This tells me that my treeview and its nodes are configured properly. So I have to assume there is a bug in the RadTreeNode.expand() client side method that is preventing it from firing the server side callback.



6 Answers, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 21 Sep 2011, 11:26 PM
Also just an fyi... I am using version 2011.2.915.40
0
Paul
Top achievements
Rank 1
answered on 23 Sep 2011, 04:30 PM
Was my explanation clear enough? Please let me know if you require further details.
0
Plamen
Telerik team
answered on 26 Sep 2011, 05:29 PM
Hello Paul,

By default the NodeExpand event is fired when the plus button is clicked as it is written in the following help topic. Please refer to our Load on Demand demo where the good practices of using the ServerSideCallback mode are shown as well.

Hope this is helpful.

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Paul
Top achievements
Rank 1
answered on 27 Sep 2011, 06:01 PM
The provided links do not have any javascript examples of how to expand a tree node using a server side callback.

When I click the plus sign on the treeview it performs the callback correctly, in the node_expand function I change the expandmode to client side.... This all works fine.

However when I call the javascript method "expand()" on a treeview node it will not work if the expand mode is set to serversidecallback.



0
Paul
Top achievements
Rank 1
answered on 27 Sep 2011, 08:01 PM
I've been digging into the treeview javascript and I believe the problem may lie somewhere in the _doLoadOnDemand function.

Here is jscript produced by the telerik controls.

_doLoadOnDemand: function (l) {
        var i = new a.RadTreeNodePopulatingEventArgs(l, null);
        this.raiseEvent("nodePopulating", i);
        if (i.get_cancel()) {
            l._properties.setValue("expanded", false);
            return;
        } var j = String.format('{{commandName:"LOD",index:"{0}",data:{1},clientState:{2}}}', l._getHierarchicalIndex(), c.serialize(l._getData()), this.saveClientState());
        if (this.get_loadingStatusPosition() != a.TreeViewLoadingStatusPosition.None) {
            l.showLoadingStatus(this.get_loadingMessage(), this.get_loadingStatusPosition());
        } var h = Function.createDelegate(this, this._onCallbackResponse);
        var k = Function.createDelegate(this, this._onCallbackError);
        WebForm_DoCallback(this._uniqueId, j, h, l, k, true);


So I decided to call this client side method directly like this.
var tree = $find("<%= rtvMain.ClientID %>");
var selectedNode = tree.get_selectedNode();
tree._doLoadOnDemand(selectedNode);

By calling the LoadOnDemand method directly it still does not seem to work.

My guess is that something is going wrong with the "WebForm_DoCallback" since I am calling the expand through postback startup script.

0
Paul
Top achievements
Rank 1
answered on 27 Sep 2011, 09:06 PM
I may have a found a solution. It appears that the expand method was being called before the previous ajax postback response was being handled.

So instead of using "ScriptManager.RegisterStartupScript" I changed it to "RadAjaxManager.ResponseScripts.Add()"

I will followup again if I encounter any further issues.
Tags
TreeView
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or