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

Performance with EnableViewState and PersistLoadOnDemandNodes

1 Answer 259 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ben Turpin
Top achievements
Rank 1
Ben Turpin asked on 03 Jul 2008, 04:25 PM
Hi

Scenario:
I have an treeview that is being loaded on the PageLoad from the DataBase.
First it fills the first root nodes then each nodeExapand event fetch the new nodes from the database.
Performance here is critical, so what I did a Ajax request with the RadAjaxManager send some parameters to the database and response back to the client, if it is successful I finish the client side operation:

Server Code:

 protected void RadAjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e) 
    { 
        string argument = e.Argument; 
        string operation = GetOperation(argument); 
        string parameters = RemoveOperation(argument); 
 
        switch (operation) 
        { 
            case "0"
                MoveMenuItemToMenu(parameters); 
                break
        } 
 
private void MoveMenuItemToMenu(string argument) 
    { 
        string[] nodes = argument.Split('|'); 
 
        string sourceMiId = nodes[0]; 
        string destMeId = nodes[1]; 
 
        bool dbResult =  MenuItemDAO.Create().MoveMenuItemToMenu(sourceMiId, destMeId); 
 
        RadAjaxManager.ResponseScripts.Add(string.Format("FinishMoveMenuItemToMenu({0})", dbResult.ToString().ToLower() )); 
 
        //System.Threading.Thread.Sleep(3000); 
    } 
 


Client Code:

function MoveMenuItemToMenu(srcNode,dstNode) 
    var sourceNodeId = GetId(srcNode.get_value()); 
    var destNodeId = GetId(dstNode.get_value()); 
     
    tempSourceNode = srcNode; 
    tempDestNode = dstNode; 
     
    var arg = "0?" + sourceNodeId + "|" + destNodeId; 
     
    sendRequest(arg); 
 
        function sendRequest(params) 
        { 
            var ajaxMan = $find("RadAjaxManager"); 
            ajaxMan.ajaxRequest(params); 
        } 
 
function FinishMoveMenuItemToMenu(success) 
    if (success) 
    { 
        tempSourceNode.get_parent().get_nodes().remove(tempSourceNode); 
        tempDestNode.get_nodes().add(tempSourceNode) 
    }else 
        alert('Operation in database did not occur'); 


I have to disable the EnableViewState to increase performance. I used Fiddler to measure the transfered data:
EnabaleViewState = true : 92.175 Bytes
EnabaleViewState = false : 1.149 Bytes (hurray!)

However (I hate howervers!), when EnabaleViewState is false, only the first root nodes are loaded, and when I try to expand a root node to show the child nodes this error appears:
"Index was out of Range. Must be non-negative and less the size of the collection.
Parameter name: Index".

Searching the telerik forums I found that if you disable the PersistLoadOnDemandNodes it will increase perfomance, but it didn't make any difference really.
EnableViewState = true
PersistLoadOnDemandNodes  = false : 92.275 Bytes.

But with "EnableViewState = true" and "PersistLoadOnDemandNodes  = false" the tree worked fine wiht no "Index was out of Range" javascript error.

However ( ¬¬ ), when EnableViewState is set to false the nodes are not persisted on the server and I can't check if a node has a father on the server, treeNode (captured from the RadTreeNodeEventArgs) has always parentNode = null.

So, how can I check the parentNode property with EnableViewState False? Im not sure how it will lower the performance loading everything every time in the PageInit event.

Thanks!






1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 04 Jul 2008, 07:47 AM
Hello Ben Turpin,

When EnableViewState is set to false you should always add the root nodes of the treeview. Otherwise you may get such errors. Setting PersistLoadOnDemandNodes to false would effectively disable accessing parent nodes of the node after postback. Also all nodes would be lost after postback due to disabled viewstate. We generally do not recommend using PersistLoadOnDemandNodes when the treeview is supposed to postback or be updated after postback. There are a few approaches you can take in order to resolve the problem:
  1. EnableViewState but store it in session - this should reduce the load on demand output
  2. Use PersistLoadOnDemand = false but avoid postbacks from the treeview. Use the RadAjaxManager isntead via the OnClientItemClicked event
  3. During NodeExpand store the treeview state in session using the GetXml method. Then during PageLoad load the treeview from the session using LoadXml.

I hope this helps,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
Ben Turpin
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or