CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

A better refresh button for asp.net pages

Yesterday I wrote a little post on a refresh button for asp.net pages. It worked but had jump through some hoops. To simulate a refresh it posted back to the original page which in turn redirected itself to itself. Which is a waste of resources. As Simone pointed out it should simpler; like a straight link out of the browser. He's right. I will use a server side hyperlink as that gives me the possibility to fiddle with its properties on the server.

This refresh button works just like the back button,  this one sets it's url to that of the page itself.

[ToolboxData("<{0}:MyRefreshLink runat=server></{0}:MyRefreshLink>")]

public class MyRefreshLink : HyperLink

{

 

    protected override void OnLoad(EventArgs e)

    {

        if (!Page.IsPostBack)

            base.NavigateUrl = Page.Request.Url.ToString();

        base.OnLoad(e);

    }

 

    [Browsable(false)]

    public new string NavigateUrl

    {

        get

        {

            return base.NavigateUrl;

        }

    }

}

In the back button post are instruction how to use the control in your projects.

Hope you'll like this one better.


Published May 19 2006, 03:55 AM by pvanooijen
Filed under:

Comments

simone_b said:

Looks better now ;) Please, don't call me "she", I'm a male :D
# May 19, 2006 4:14 AM

pvanooijen said:

:)
Sorry about your name. Corrected. Over here every Simone is a she.
# May 19, 2006 4:22 AM

simone_b said:

That's fine, thanks!
# May 19, 2006 6:19 AM

Firoz Ansari said:

Still I am not sure if it will simulate exactly like Refresh button of browser. Here is my explaination why it will not work:

http://www.firoz.name/2006/05/20/a-better-refresh-button-for-aspnet-pages/
# May 20, 2006 3:13 AM

pvanooijen said:

Firoz,

Both the refresh button of your browser and this button will clean up all viewstate. That's their intention ! You observation on my button is right, your observation on the browser-regfresh button is (in IE and FF for sure) wrong.
# May 20, 2006 8:55 AM

Firoz Ansari said:

Got it!
# May 20, 2006 9:56 AM

Peter's Gekko said:

Your browser has a back, forward and refresh button. Some time ago I wrote a little post on a back button...
# May 22, 2006 5:28 AM

Travis.Net.Blog said:


Ajax Activity Indicators&amp;nbsp;(DotNetKicks)
FileHelpers Library (DotNetKicks)
ASP.NET Refresh Button...
# May 30, 2006 1:27 PM

Pantle said:

mmmmm

# August 15, 2007 11:43 PM

vishal shujalpurkar said:

Good code

# August 21, 2007 9:23 AM

Tushar Phatale said:

This code helped me alot

# August 21, 2007 9:40 AM

A said:

A

# February 17, 2008 5:36 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication

News