Hi Brian,
Though the <META HTTP-EQUIV=Refresh CONTENT ... > html header is ok for
contantly refreshing a page, but since you also need to let the enduser
start and stop the refreshing, I think maybe use javascript function to
auto refresh(in fact we do it via submit the page) is better. We can just
use the
"window.setInterval()" and "document.forms[0].submit()" to autopost the
page. And since the
"window.setInterval()" will return a timeid , we can store it in a page
scope javascript variable and then when user want to stop the autopostback,
we just cancel the Interval via this timeid. Also, we need to put an
additioal html intput hidden element to store the current state (start or
stop) so that when the after post back, we can remain the page's last
state. Anyway, to make it clear, here is a simple demo page I've made, you
can have a test on your side to see whether it works:
===============aspx page===================
<HTML>
<HEAD>
<title>autorefresh</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
var tid;
function ControlRefresh(btn)
{
var hd = document.getElementById("hdState");
if(btn.value == "Start")
{
tid = window.setInterval("AutoRefresh()",3000);
btn.value = "Stop";
hd.value = "on";
}
else
{
window.clearInterval(tid);
btn.value = "Start";
hd.value = "off";
}
}
function AutoRefresh()
{
document.forms[0].submit();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td><INPUT id="btnControl" type="button" value="Start"
onclick="ControlRefresh(this)"></td>
</tr>
<tr>
<td><INPUT id="hdState" type="hidden" name="hdState" runat="server"
value="off"></td>
</tr>
<tr>
<td>
<asp:Button id="btnPostBack" runat="server" Text="Server Button Post
Back"></asp:Button></td>
</tr>
</table>
</form>
</body>
</HTML>
=============code behind=================
public class autorefresh : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnPostBack;
protected System.Web.UI.HtmlControls.HtmlInputHidden hdState;
private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack)
{
Response.Write("<br>Page_Load fired at: " +
DateTime.Now.ToLongTimeString());
if(hdState.Value == "on")
{
Page.RegisterStartupScript("init_refresh","<script
language='javascript'>document.getElementById('btn Control').click();</script
");
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.btnPostBack.Click += new
System.EventHandler(this.btnPostBack_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnPostBack_Click(object sender, System.EventArgs e)
{
Response.Write("<br>Server Button is clicked at: " +
DateTime.Now.ToLongTimeString());
}
}
==============================
Hope helps. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)