A better refresh button for asp.net pages

Peter has modified his Refresh user control and page will now only redirect to itself that will save one server trip: A better refresh button for asp.net pages

But this modified control will again not exactly solve the existing problem. Redirecting page will not exactly behave like refresh button functionality, as after redirecting to the same page you will going to get new instance of the page, which mean you should loose all values in ViewState, Hidden Field etc. which had been modified with some back post event.

To present my point, simply place a simple button in the page, and on its click event, add some value in ViewState:

private void Button1_Click(object sender, System.EventArgs e)
{
    ViewState["Value"] = "100";
    Label1.Text = (string) ViewState["Value"];
}

with that, also display the value of this ViewState key in page load event.

private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text = (string) ViewState["Value"];
}

With above implementation in place, when user click on RefreshLink control, the value displayed from ViewState will be blank and NOT 100. But if Button1 is behaving like refresh button functionality, it suppose to show value 100.

Instead of that, my suggestion is to submit the form itself, page will then behave like Refresh button.

HyperLink1.Attributes.Add("onclick", "document.Form1.submit();");

When user click on HyperLink1 using above snippet, page will display same ViewState value which has been modified before. It's behaving exactly like Refresh button.

Here is my suggested RefreshLink control implementation:

[ToolboxData("<{0}:MyRefreshLink runat=server></{0}:MyRefreshLink>")]
public class MyRefreshLink : HyperLink
{
    protected override void OnLoad(EventArgs e)
    {
        base.Attributes.Add("onclick", "document.Form1.submit();");
        base.OnLoad(e);
    }

    [Browsable(false)]
    public new string NavigateUrl
    {
        get
        {
            return base.NavigateUrl;
        }
    }
}