Thursday, 22 October 2009

Simple Auto Refresh of ASP.NET Page

I have a 'log viewer' page in one of my projects which I need to refresh every ten seconds.

There are lots of ways to achieve this using JavaScript and nasty code behind bodge jobs but there's a much easier way that only requires one line of code.

<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<!--The next line of code will refresh the page every 10 seconds-->
<meta http-equiv="refresh" content="10">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=""

Clearly, content="10" means the interval in seconds.