Home - Forums-.NET - FlyTreeView (ASP.NET) - Client-side Select() and Postbacks

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Client-side Select() and Postbacks
Link Posted: 17-Aug-2008 10:59
I have setup my flytreeview inside an update panel to postback on node selection.  During the postback on the server, I'm sending back the node I want to be selected on the client.  So, I find the node and call its select function on the client.  However, if this node is not the node that is currently selected, it will postback to the server again.  Is there a way to disable the postback functionality when selecting a node on the client?

Here's the client code I'm using:


    var _treeview;
    function initializeTreeView(sender)
    {
        _treeview = sender;
    }

    // handler for update panel's endRequest event
    function endRequest(sender, args)
    {
        // get the selected node id from the response
        var newPageValue = args.get_dataItems().ProposalTree
        if(typeof(newPageValue) == "string")
        {
            var node = _treeview.findByValue(newPageValue);
            if(node)
            {
                // THIS WILL CAUSE A POSTBACK IF THE CURRENTLY SELECTED NODE
                // DOES NOT EQUAL THIS NODE.
                node.select();
            }
            else
            {
                alert("Unable to find the node by id.  ID: " + newPageValue);
            }
        }
        else
        {
            alert("Unable to retrieve the page id from the response.");
        }      

.
.
.




Also, the reason I do not set the selected node on the server is because of the size of html sent back for the flytreeview.  My response size is doubled if I programatically update the flytreeview's update panel.
Link Posted: 17-Aug-2008 17:12
You can create handle for OnSelectedNodeChangedJavascript and return false for required cases.
This will prevent flytreeview from postback.
See the following page for event details:
http://www.9rays.net/asp.net_2/treeview/miscpages/doc/ClientEvents.aspx

P.S. There also can be several "hacks" to prevent treeview from posting back when you select node.
For example, you can just temporarily replace __doPostBack function of ASP.NET:

var originalDoPostBack = window.__doPostBack;
// replace with function that does nothing
window.__doPostBack = function(){};
node.select();
// restore original function
window.__doPostBack = originalDoPostBack;
Link Posted: 18-Aug-2008 04:40
I'll give it a try ... thanks.