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.setInte rval()" and "document.f orms[0].submit()" to autopost the
page. And since the
"window.setInte rval()" 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>autorefr esh</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script language="javas cript">
var tid;
function ControlRefresh( btn)
{
var hd = document.getEle mentById("hdSta te");
if(btn.value == "Start")
{
tid = window.setInter val("AutoRefres h()",3000);
btn.value = "Stop";
hd.value = "on";
}
else
{
window.clearInt erval(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="Contro lRefresh(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>
=============co de behind========= ========
public class autorefresh : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Butt on btnPostBack;
protected System.Web.UI.H tmlControls.Htm lInputHidden hdState;
private void Page_Load(objec t sender, System.EventArg s e)
{
if(IsPostBack)
{
Response.Write( "<br>Page_L oad fired at: " +
DateTime.Now.To LongTimeString( ));
if(hdState.Valu e == "on")
{
Page.RegisterSt artupScript("in it_refresh","<s cript
language='javas cript'>document .getElementById ('btnControl'). click();</script
");
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
InitializeCompo nent();
base.OnInit(e);
}
private void InitializeCompo nent()
{
this.btnPostBac k.Click += new
System.EventHan dler(this.btnPo stBack_Click);
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
private void btnPostBack_Cli ck(object sender, System.EventArg s e)
{
Response.Write( "<br>Server Button is clicked at: " +
DateTime.Now.To LongTimeString( ));
}
}
=============== ===============
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.)