RIA Practices

Quick Search

Advanced Search »
Edit

Problem statement

Refresh

Refresh

Many RIA applications forget about the page refresh and back button. By default, when the user hits refresh, the application unloads, reloads and starts over from the beginning forcing the user to navigate back to the where they were in the first place. By default when the user hits the back button, the page with the application in it is unloaded as the browser goes back in the history to the previous page. In either case, this is probably not what the user expected.

Edit

Default Action

If they were using a traditional HTML based web application the refresh would simply reload the page that they are on. If there was a postback involved, it will even offer the user the possibility to repost those variables to get the same result again. You can, if you write code to handle it in the unload and load of the application write out the state on unload and recreate the state on load.

For the back button, things are little bit more complicated. One way you can handle this is to build a state machine that tracks the logical pages in your application such as the pages in a wizard. Then you can trap the back button event and unwind the state machine. If you are at the beginning of the application, let the event go and act as normal.

Edit

What you should not do

There are a lot of ways that you can deal with the page refresh. One mechanism for doing this is to capture the exit or unload event from the application and save off the state. On startup of the application, you can evaluate that state and decide if the state is still valid and reload it if applicable. A low tech solution is to check a timestamp on the state and decide based on that.

Edit

Silverlight example

Overly simplistic Silverlight example: C#:
public partial class App : Application
...
private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new Page();

string dateUnloaded = CookieManager.GetCookie("dateUnloaded"); string state = CookieManager.GetCookie("state"); if (dateUnloaded != null && state != null) { DateTime dateLastUnloaded = DateTime.Parse(dateUnloaded); if (DateTime.Now.Subtract(dateLastUnloaded) < TimeSpan.FromSeconds(20)) { (this.RootVisual as Page).Message = state; CookieManager.DeleteCookie("dateUnloaded"); } } }

private void Application_Exit(object sender, EventArgs e) { CookieManager.SetCookie("dateUnloaded", System.DateTime.Now.ToString()); CookieManager.SetCookie("state", (this.RootVisual as Page).Message); } ... }

ScrewTurn Wiki version 2.0.34. Some of the icons created by FamFamFam.