Your browser has a back, forward and refresh button. Some time ago I wrote a little post on a back button to include on your own asp.net pages. According to the feedback you liked that one. Here I would like to share a refresh button. Quite simple and it works well! Although not as simple as the better version which resulted from the feedback on this one,
You work with this code just like the back-button. This is the code
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace WebControlLibrary
{
/// <summary>
/// Summary description for MyRefreshButton.
/// </summary>
[ToolboxData("<{0}:MyRefreshButton runat=server></{0}:MyRefreshButton>")]
public class MyRefreshButton : System.Web.UI.WebControls.LinkButton
{
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
Page.Response.Redirect(Page.Request.Url.ToString(), true);
}
}
Also this one is a descendent of the linkbutton. When it's clicked it redirects the response to the url of the page itself. Which will start a new series of roundtrips. Your page will have it's initial state again.
The actual behavior is not quite the same as that of the browser's refresh buttonn
- Before issuing the redirect any click handlers are invoked in the base.OnClick(). In there you could do some things to save work.
- Due to the way the page lifecycle works pageload and other eventhandlers will be executed before the redirect. Using the browser button these will not fire. The page prerender will not fire.
The better version does not have this extra behavior.
Hope you like it
Posted
Thu, May 18 2006 4:37 AM
by
pvanooijen