Replacing the expandedNodes cookie

5 posts, 0 answers
  1. Paul Robertson
    Paul Robertson avatar
    78 posts
    Member since:
    May 2010

    Posted 03 Dec 2012 Link to this post

    Hi there

    I have a radTreeView for which I save the expansion status before postback, using the dynamically generated 'expandedNodes' cookie, as is standard. However, I want to be able replace the cookie with one I have created in my server-side PreRender handler for the radTreeView control.

    I can rewrite the value of the cookie OK, the problem is when I do so, and add the new cookie using the same name, the old cookie is not replaced, and I end up with two 'expandedNodes' cookies, which evidentally confuses the radTreeView, which ignores both the cookies. I want to replace the old cookie originally generated by the control, to use the server-side version generated by my code, which as far as I am aware uses the correct technique as follows:

                        Dim cookie As HttpCookie = New HttpCookie("expandedNodes")
                        cookie.Value = newcookievalue    // Setup earlier by constructing '*' delimited expansion route
                        cookie.Expires = DateTime.Now.AddDays(1)
                        Response.Cookies.Add(cookie)

    after which, at the end of the PreRender handler, the Response.Cookies collection only has 1 expandedNodes cookie, the one I have just added here. But then after the postback is complete, this cookie is ADDED rather than REPLACING the existing cookie of the same name.

    How can I get the radTreeView to use the new cookie, instead of the old one? That is, how can I delete the old cookie, which currently seems to be restored by the radTreeView, in addition to the cookie my code is adding. Is this a problem involving some combination of  the ExpandMode property or the Viewstate?

    What would be the best approach to this issue?

    Regards

  2. Paul Robertson
    Paul Robertson avatar
    78 posts
    Member since:
    May 2010

    Posted 11 Dec 2012 Link to this post

    Hi folks

    I really could do with some advice on this problem. Am I going about it the wrong way - to summarize, I want to customize the expandedNodes cookie in the server side code during a postback, and then get the radTreeView to use the new customized cookie rather than the original one, i.e., replace or delete the original cookie.

    Thanks if you can tell me if this is not going to work, as I'm getting nowhere with it at the moment.

    Regards

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 14 Dec 2012 Link to this post

    Hello,

    Please find our code library resource that demonstrates an approach of setting value to expandedNodes cookie and retrieves that data in the code behind. You could access that cookie using the following syntax and modify it:
    HttpCookie cookie = Request.Cookies["expandedNodes"];

    Kind regards,
    Boyan Dimitrov
    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.
  5. Paul Robertson
    Paul Robertson avatar
    78 posts
    Member since:
    May 2010

    Posted 14 Dec 2012 Link to this post

    Hi

    That's not really what I was asking, as hopefully it should be clear that I've already got that far - I have processed the Request cookie successfully back at server-side after postback. The issue I have is afterwards - I can also include a custom Response cookie that is used back at the client to expand nodes again. Unfortunately this approach seems to be flawed, as there appears to be a remnant cookie appearing back at the client that can interfere with my new custom cookie, and it is this remnant cookie that I seek to replace, rather than duplicate. I can't see where the remnant cookie is appearing from.

    After having time now to work on it a bit further, maybe it would be better to rephrase the issue as a more explicit question: does the radTreeView keep a copy of the expandedNodes cookie in its ViewState, which it then reintroduces automatically when it receives the response page back from my server-side code? If so, what is the best way of deleting it so it does not interfere with the new expandedNodes cookie reintroduced through the server-side code?

    Thanks very much

  6. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 17 Dec 2012 Link to this post

    Hello,

    Since we do not keep our RadTreeView nodes expanded state in a cookie you could implement the desired functionality by creating an entirely separate cookie in order to keep track of expanded nodes and modify them.

    Regards,
    Boyan Dimitrov
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017