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

Replacing the expandedNodes cookie

4 Answers 65 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Paul Robertson
Top achievements
Rank 1
Paul Robertson asked on 03 Dec 2012, 07:09 PM
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

4 Answers, 1 is accepted

Sort by
0
Paul Robertson
Top achievements
Rank 1
answered on 11 Dec 2012, 10:55 AM
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

0
Boyan Dimitrov
Telerik team
answered on 14 Dec 2012, 09:59 AM
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.
0
Paul Robertson
Top achievements
Rank 1
answered on 14 Dec 2012, 04:06 PM
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

0
Boyan Dimitrov
Telerik team
answered on 17 Dec 2012, 03:32 PM
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.
Tags
TreeView
Asked by
Paul Robertson
Top achievements
Rank 1
Answers by
Paul Robertson
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or