treenode and client side APIs

4 posts, 2 answers
  1. Andrea
    Andrea avatar
    64 posts
    Member since:
    Jan 2005

    Posted 19 May 2008 Link to this post

    Hi all,
    i'm trying to use some treeview client side function.

    For example, I manage client side node checked event, and i set imageUrl, Category, image alt attribute and some other stuff, depending on treenode. checked value.

    All works really good since I submit my changes with a button postback...

    The only changes i get server side is the checked value, but all other properties and attributes are lost.

    Here is an example of what functions i'm using from APIs.
    Any idea about how can I get changed values server side?
       function SwitchEditMode(menuItem, treeNode)  
                   {    
                      if(treeNode.get_checked() == true)  
                      {  
                        switch(menuItem.get_value())  
                        {  
                            case "0":  
                                treeNode._imageElement.alt = ReadOnlyMsg;  
                                treeNode.get_element().all[4].title=ReadOnlyMsg;  
                                treeNode.set_selectedImageUrl(imageReadOnlyUrl);  
                                treeNode.set_imageUrl(imageReadOnlyUrl);  
                                treeNode.set_category("0");  
                                break;  
                            case "1":  
                                treeNode._imageElement.alt = EditableMsg;  
                                treeNode.get_element().all[4].title=EditableMsg;  
                                treeNode.set_selectedImageUrl(imageEditableUrl);  
                                treeNode.set_imageUrl(imageEditableUrl);  
                                treeNode.set_category("1");  
                                break;  
                        }  
                      }    
                    } 

    Thank you
  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 May 2008 Link to this post

    Hi Andrea,

    Only properties are persisted server-side. Any HTML Dom attributes such as "alt" will not be persisted.
    One of the options is to save these attributes as custom attributes of the nodes and load them in pageLoad().

    To save the properties like selectedImageUrl and category you need to wrap them with tree.trackChanges() and tree.commitChanges() methods:

      function SwitchEditMode(menuItem, treeNode)   
                   {     
                      if(treeNode.get_checked() == true)   
                      {   
                        var tree = treeNode.get_treeView(); 
                        tree.trackChanges(); 
                        switch(menuItem.get_value())   
                        {   
                            case "0":   
                                treeNode._imageElement.alt = ReadOnlyMsg;   
                                treeNode.get_element().all[4].title=ReadOnlyMsg;   
                                treeNode.set_selectedImageUrl(imageReadOnlyUrl);   
                                treeNode.set_imageUrl(imageReadOnlyUrl);   
                                treeNode.set_category("0");   
                                break;   
                            case "1":   
                                treeNode._imageElement.alt = EditableMsg;   
                                treeNode.get_element().all[4].title=EditableMsg;   
                                treeNode.set_selectedImageUrl(imageEditableUrl);   
                                treeNode.set_imageUrl(imageEditableUrl);   
                                treeNode.set_category("1");   
                                break;   
                        }   
                        tree.commitChanges(); 
                      }     
                    }  

    I hope this helps.

    Sincerely yours,
    Veskoni
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 May 2008 Link to this post

    Hello Andrea,

    I have one more suggestion: do not use private members like treeNode._imageElement
    It is always a good practice to use the public method: treeNode.get_imageElement()


    Regards,
    Veskoni
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Andrea
    Andrea avatar
    64 posts
    Member since:
    Jan 2005

    Posted 21 May 2008 Link to this post

    ok it's working fine, really thank you for your suggestion.
Back to Top