Welcome Guest Search | Active Topics | Sign In | Register

TreeView and the browser's back button Options
Ken Klose
Posted: Tuesday, November 6, 2012 8:15:23 AM
Rank: Newbie
Groups: Member

Joined: 11/6/2012
Posts: 3
I have a TreeView control with checkboxes in a page that posts back. If the user then clicks the browser's back button the TreeView control is back in it's original state, it doesn't keep the items selected that the user selected. Is there a way to accomplish this?

Many Thanks,
Ken
eo_support
Posted: Tuesday, November 6, 2012 8:36:14 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

There is no way to reliably implement this. You will want to warn your user against using the back button. The TreeView is not a simple input control, rather it's dynamically initialized by JavaScript. So when you click back button the initialization script is run again thus clears everything.

Thanks!
Ken Klose
Posted: Tuesday, November 6, 2012 9:50:31 AM
Rank: Newbie
Groups: Member

Joined: 11/6/2012
Posts: 3
Hi,

Would it be feasible to use the TreeView's client-side API to scrape the state of the TreeView into a hidden form field onsubmit and then on page load take the state out of the hidden form field and use the API to select the correct checkboxes? Or is there a known problem with this approach?

Thanks,
Ken
eo_support
Posted: Tuesday, November 6, 2012 7:18:11 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

The TreeView's client side API will always work. However as far as we know there is no reliable way to detect the back button click. So it would be pretty much a dead end.

Thanks!
Ken Klose
Posted: Friday, November 9, 2012 11:04:11 AM
Rank: Newbie
Groups: Member

Joined: 11/6/2012
Posts: 3
Hi,

I've succeeded (at least in my target browser IE). I don't need to detect the back button click. I have two javascript functions. The first runs in response to the window.onload event. It looks at a hidden form field, if the field has data in it then the function deserializes it into an object which represents the last state of the TreeView control when the page was submitted and then uses the TreeView client API to rehydrate the appropriate check boxes in the TreeView.

I have another function which executes with the forms onsubmit event. It gets the checked nodes from the TreeView client API, puts this data into an object and then serializes that object to a JSON string and puts it into the hidden form field. This form field is submitted, but the server code ignores the hidden form field. However when you click the back button the browser repopulates form fields (including hidden form fields) with the data they contained when submitted. Thus the state of the TreeView is preserved. The window.onload function reads the data and restores the TreeView state.

Thanks,
Ken
eo_support
Posted: Friday, November 9, 2012 12:21:23 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Glad to hear that you worked out a solution for that and thanks for sharing!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.