Last post Mar 03, 2008 11:45 AM by tgakk
Feb 25, 2008 11:15 PM|tgakk|LINK
I haven't been able to make this work... Here's my situation: I have a page where a user can edit their profile. I'm using 3 cascadingdropdowns for city, state, country. The dropdowns work great and on page load get populated with the city, state, country
they registered with. The user can make changes and then save it. All works fine. But, if the user clicks the back button after having saved their new city, state, country, the cascadingdropdowns get filled with the original values instead of the new values
they selected. I was hoping to use the extensions preview and the new history method of scriptmanager to have it remember the new values they chose in the cascadingdropdowns but I can't get it to work.
Here's some snippets from my code:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableHistory="true" OnNavigate="OnNavigateHistory" EnableStateHash="false">
This is inside the content tag (I have a master page attached to this page)
<script runat="server"> Private Shared key As String = "s"
' Handle the Navigate event
Public Sub OnNavigateHistory(ByVal sender As Object, ByVal e As HistoryEventArgs) CascadingDropDown3.SelectedValue = Server.HtmlEncode(e.State("city")) CascadingDropDown2.SelectedValue = Server.HtmlEncode(e.State("state")) CascadingDropDown1.SelectedValue = Server.HtmlEncode(e.State("country")) End Sub
' On button click, handle the event and set a history point.
Public Sub ButtonClick(ByVal sender As Object, ByVal e As EventArgs) 'LabelHistoryData.Text = CType(sender, Button).Text
ScriptManager.GetCurrent(Me).AddHistoryPoint("city", ddlCity.SelectedValue) ScriptManager.GetCurrent(Me).AddHistoryPoint("state", ddlState.SelectedValue) ScriptManager.GetCurrent(Me).AddHistoryPoint("country", ddlCountry.SelectedValue) End Sub
On my submit button definition I have OnClick="ButtonClick"
How can I make the cascadingdropdowns remember their previous values when the back button was clicked instead of reverting to their original values before the user made any changes?
Feb 26, 2008 12:00 AM|norchnou|LINK
Either try to:
Set enableHistory and EnableViewState to false on your dropdownlists
or to :
rebind your control on the PageLoadEvent
Let me know if it worls
Feb 26, 2008 09:19 AM|tgakk|LINK
Thanks for the reply. I have enableHistory set as in my code in my first post. I tried setting EnableViewState to false on the dropdownlist itself and got the same result. I then set EnableViewState to false on the cascadingdropdown extender as well
and then tried EnableViewState = false on just the Cascadingdropdown extender. All the same results--it remembered its initial values when the person first went to the page, but not their updated values after they had submitted them.
The problem with rebinding is that when you click the back button, it doesn't fire any events, so I can't rebind. The only way I know of to get it to refire events is to expire the page from the cache, but the problem I normally have with doing that is
that it often tells the user that the last page has POST data and do they want to resubmit. I don't want my users to have to see that message. Is there a better way to do this that doesn't result in the POST message popping up? I'd really like to just be
able to click back and have the cascadingdropdowns remember the last values that were selected, like all the other controls do.
But, just to see if it worked, I tried expiring the page and it did rebind successfully (I'm using session variables to remember the selected values). I'll try it on the rest of my pages tonight to make sure I don't get the POST message, but I still think
there has to be a better way. One note is that I had to make sure on the scriptmanager that enablepartialrendering was set to true for the rebinding to even work.
Weird that adding history points with the preview isn't helping. Maybe I'm just doing it wrong.
Any other thoughts on how to make this work without expiring the page forcing a rebind?
Feb 26, 2008 10:14 PM|norchnou|LINK
maybe an update panel will do it.
or try to catch the origin of the user and then create your rule.
Feb 27, 2008 01:32 PM|tgakk|LINK
Thanks for the reply. I haven't had any luck getting this to work and I've wasted way too much time on it, so I'm going to use normal dropdowns in an update panel and just write my own routines to cascade them instead of the cascadingdropdown toolkit controls.
Feb 29, 2008 03:39 PM|norchnou|LINK
you can use the PageLoad Event
On this event reBound all your dropdown list
Mar 03, 2008 11:45 AM|tgakk|LINK
The problem is that to get the pageload event to fire on the back button being pressed, you have to expire the page, which has never led to great results for me (either the user gets a message about POST data, which isn't a very friendly message, or I have
to use sessions which makes it more complicated than it ought to be). I've given up on the cascadingdropdown, so I just wrote my own cascading dropdowns (non ajax) that meet my need. Other controls remember their viewstate's just fine. I really though the
enableHistory with the new 3.5 extensions preview would solve my issue.
Thanks everyone for the help.