473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

auto refresh web page

hello,
I am looking for a way to auto refresh a web page that I created, but
also let the user choose to stop the auto refresh. I can not figure out how
to stop the auto refresh. Any help would be appreciated.

Thanks,
Brian
Nov 21 '05 #1
7 22650
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Me.CheckBox1.Checked Then
Context.Response.AddHeader("REFRESH", "2")
End If
End Sub

Set CheckBox1.AutoPostBack= True

"Brian" wrote:
hello,
I am looking for a way to auto refresh a web page that I created, but
also let the user choose to stop the auto refresh. I can not figure out how
to stop the auto refresh. Any help would be appreciated.

Thanks,
Brian

Nov 21 '05 #2
Hi Brian,

you can use too:
Enable Auto-Refresh (5 seconds):
Response.Write("<META HTTP-EQUIV=Refresh CONTENT='5'>")
Disable Auto-Refresh:
Response.Write("<META HTTP-EQUIV=Refresh CONTENT='5'>")

I hope that helps.

Jorge Serrano Pérez
MVP VB.NET

"Brian" wrote:
hello,
I am looking for a way to auto refresh a web page that I created, but
also let the user choose to stop the auto refresh. I can not figure out how
to stop the auto refresh. Any help would be appreciated.

Thanks,
Brian

Nov 21 '05 #3
I'm sorry, my fingers have been too fast! O:-)

Disable Auto-Refresh;
Response.Write("<META HTTP-EQUIV=Refresh CONTENT=''>")

Now it's ok.


"Jorge Serrano [MVP VB]" wrote:
Hi Brian,

you can use too:
Enable Auto-Refresh (5 seconds):
Response.Write("<META HTTP-EQUIV=Refresh CONTENT='5'>")
Disable Auto-Refresh:
Response.Write("<META HTTP-EQUIV=Refresh CONTENT='5'>")

I hope that helps.

Jorge Serrano Pérez
MVP VB.NET

"Brian" wrote:
hello,
I am looking for a way to auto refresh a web page that I created, but
also let the user choose to stop the auto refresh. I can not figure out how
to stop the auto refresh. Any help would be appreciated.

Thanks,
Brian

Nov 21 '05 #4
Thanks. I only have one problem. I have a button that I change the text of
from Start to Stop and vice versa, but the code only sees the first setting
"Stop" The form updates, but the code never sees the new value "Run". I
hope that was clear enough. Any Ideas?

Thanks,
Brian

"Jorge Serrano [MVP VB]" wrote:
I'm sorry, my fingers have been too fast! O:-)

Disable Auto-Refresh;
Response.Write("<META HTTP-EQUIV=Refresh CONTENT=''>")

Now it's ok.


"Jorge Serrano [MVP VB]" wrote:
Hi Brian,

you can use too:
Enable Auto-Refresh (5 seconds):
Response.Write("<META HTTP-EQUIV=Refresh CONTENT='5'>")
Disable Auto-Refresh:
Response.Write("<META HTTP-EQUIV=Refresh CONTENT='5'>")

I hope that helps.

Jorge Serrano Pérez
MVP VB.NET

"Brian" wrote:
hello,
I am looking for a way to auto refresh a web page that I created, but
also let the user choose to stop the auto refresh. I can not figure out how
to stop the auto refresh. Any help would be appreciated.

Thanks,
Brian

Nov 21 '05 #5
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.)
Nov 21 '05 #6
Thanks for the reply. Unfortunatly I had to rush the program into
production, so I ended up making a second web page the was a copy of the
first with out the counter. I will give this a try though and see if I can
improve what I have now. Thanks. Brian

"Steven Cheng[MSFT]" wrote:
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.)

Nov 21 '05 #7
Hi Brian,

Thanks for your followup. Well, if you meet any further problem in the
furture or need any other assistance, please feel free to post here. 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.)

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Scott | last post by:
I have a clickable graph that resides on page 1. If user clicks a data point on the graph, the page runs again yeilding a 2nd graph that shows a more detailed graph. Problem is, I have a...
1
by: Lew | last post by:
Hi all, I'm trying to create a page that has a user-selectable page auto-refresh option (IE 5.5). Essentially, it's a page that contains a checkbox, when the user checks the checkbox, I'd like...
0
by: Marcus | last post by:
Hello! I'm buildning a webpage in ASP.NET using Visual Basic. The page contains a datagrid, a dropdownlist, some textboxes and a couple of buttons. The datagrid displays barcodes from a table...
3
by: Ronald S. Cook | last post by:
I want to have a web page that shows the first 10 records of data. I want it to wait 10 seconds and then show then next 10 records. How can I do this? This is for events like what you'd see on...
10
by: phforum | last post by:
Hi, I wrote a PHP page for user input the information to search the database. And the database data will update every second. I want to set the auto refresh to get the data from database every...
3
by: tinuananster | last post by:
Hi, I need to auto refresh a page after a specific time interval. When the page is accessed the first time, a request parameter is null and hence it gets redirected to a welcome page (static...
2
by: ankitmathur | last post by:
Hi Fellow Members, I want to know if HTML provides any way of refreshing a page only once automatically. My requirement is to refresh a page automatically only once after 2 minutes to display...
2
by: =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post by:
Hi I have a web page that has a TreeView on it. If I DONT'T expand the TreeView nodes, the auto refresh works nicely: my page gets refreshed every minute. As soon as I expand a node on the...
3
by: tvnaidu | last post by:
How to auto refresh page for every 3 minutes by passing command part of URL?. I need to refresh one page automatically by passing that refresh command part of url, for example if I want to refresh...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.