2012年3月26日月曜日

Retaining ViewState in Atlas

On my real estate website I have a Search page and a Results page. The Search page contains three linked Atlas cascading dropdowns (CDDs). The user makes some selections on these and then clicks a <search> button to see the results. This opens the Results page, which displays a list of properties meeting the search criteria. I have this working fine, apart from one thing: when the user goes back to the Search page, the CDDs have been reset to their original values. I was wondering if there was an easy way for the Search page to retain its settings. I have a partial solution, but it's not very good. If I set AutoPostBack to "True" for each CDD, they retain their settings when I click the <back> button on the browser. This is pretty horrible though, as it means the whole page gets posted back - undermining the whole purpose of using Atlas in the first place! I have tried enclosing the CDDs in an UpdatePanel (so that only they get posted back and not the whole page), but they just end up flickering all the time as (I guess) they get stuck in a code loop.

Also, setting AutoPostBack to "True" is only effective when the user clicks the browser's <back> button. I want to offer my own button or link in case they arrived at the Results page from another route. I have tried creating a hyperlink to the Search page, adding a button with a PostBackUrl of "Search.aspx" and adding a Response.Redirect command to a button's on_click event. Even with AutoPostBack set to "True" (which I want to avoid), none of these methods works. The CDDs just get reset every time.

Also, the other server controls I have on the Search page (check boxes, conventional drop-down list boxes, etc.) get reset every time too. I've tried looking into ViewState, but I can't get it to work. It looks like I need a way to save the viewstate on exit and somehow retrieve it when I load the page again. I guess I'm missing something fundamental. Any suggestions? Am I barking up the wrong tree? I imagine this kind of thing must have been done many times before and would appreciate a few hints.Any ideas on this? I'd really appreciate some help on something that must be a fairly common problem - or will be as Atlas takes off. Thanks for your interest.

You could try saving the viewstate to sessionstate or to disk

An example of saving viewstate to disk can be found here :
http://aspalliance.com/911


That seems to be on the right track. I'm now saving the values of my page controls to Session State when I exit the page, and retrieving them when I load it. This works fine for all the controls except the CDDs. Since these are populated by WebMethods, I don't seem to have any opportunity to set their SelectedValue properties. To focus on the problem area, I have tried adding a button to my form with a single line of code reading:ddlRegion.SelectedValue = RegionIDWhere RegionID is a value retrieved from the session.This causes an argument out of range exception as follows:[ArgumentOutOfRangeException: 'ddlRegion' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value]I get the same error if I change the variable RegionID to the literal "1" (which is definitely in the list).What it boils down to is this:How can I programatically set the SelectedValue of an Atlas Cascading Dropdown?I know how to save the value to, and retrieve it from, session state, but I don't know how to assign it to an Atlas cascading dropdown list. Any ideas?

1. Perest the CCD by setting the selected value of the cascading extender control ( and not the drop-down) , as explained in the article ( link )

2. and you can retrieve the viewsate ... as explained on this link.http://gandhirohan.blogspot.com/2007/09/cascadingdropdown-control.html

0 件のコメント:

コメントを投稿