Deserialize RadTreeNode from toJsonString

4 posts, 0 answers
  1. Roatin Marth
    Roatin Marth avatar
    65 posts
    Member since:
    Nov 2007

    Posted 02 Sep 2009 Link to this post

    The RadTreeNode js class has the function toJsonString, but what good is it without a function to deserialize it back into a RadTreeNode object.

    I tried using _loadFromDictionary but it didn't seem to work and it is a private method.

    Am I missing something?

    Thanks
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 03 Sep 2009 Link to this post

    Hi Roatin Marth,

    The usage of the toJsonString method is shown in this example. There the string is used on the server-side. Currently the _loadFromDictionary method accepts a JSON object rather than string so it cannot be used. Could you please let us know your requirements?

    Sincerely yours,
    Atanas Korchev
    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. UI for ASP.NET Ajax is Ready for VS 2017
  4. Roatin Marth
    Roatin Marth avatar
    65 posts
    Member since:
    Nov 2007

    Posted 03 Sep 2009 Link to this post

    I need to be able to serialize and deserialize a node on the client side.  I have a node with several attributes, text, image etc. that I need the app to be able to remember.  Whats happening is I'm working on a page that still uses post backs in some cases which causes the client side state to be wiped out.  So I'm serializing this special node (It's not a selected node, just a special node I want to remember)  and sticking it in a hidden field so after a postback I have the ability to bring it back into the client side.

    However at this point there is no equivalent function to deserialize in the client side.  So thats what I'm missing.

    By the way I tried calling Sys.Serialization.JavaScriptSerializer.deserialize() before _loadFromDictionary and it still didn't work.

    Thanks
  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 04 Sep 2009 Link to this post

    Hello Roatin Marth,

    Find below some sample code which works as expected at my side:

            <asp:ScriptManager ID="RadScriptManager1" runat="server" />
            <telerik:RadTreeView runat="server" ID="RadTreeView1">
                <Nodes>
                    <telerik:RadTreeNode Text="Root" />
                </Nodes>
            </telerik:RadTreeView>
         
            <script type="text/javascript">
                function pageLoad(){
                    var treeView = $find("<%= RadTreeView1.ClientID %>");
                    var firstNode = treeView.get_nodes().getNode(0);
                    var jsonAsString = firstNode.toJsonString();
                    alert(jsonAsString);
                    var node = new Telerik.Web.UI.RadTreeNode();
                    node._loadFromDictionary(Sys.Serialization.JavaScriptSerializer.deserialize(jsonAsString));
                    firstNode.get_nodes().add(node);
                }
            </script>

    What is different in your case?

    Regards,
    Albert
    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.
Back to Top