but the page will keep refreshing for every few seconds, is there a way to make it just refresh once only??? If this code can't do it, is there any other VB code sample I can use?
You have to inject this javascript code to the page one time and not everytime the page is executed on the server. This is why you need a variable to indicate that now i want to refresh the page
Thanks for the reply. The previous codes I have found are actually from your old reply to another topic,[:D] I really appreciate your help. I have added if(Request.QueryString["r"] != null) at my page_load event, but I got error when I run the page, it said:
BC30311: Value of type 'System.Collections.Specialized.NameValueCollection' cannot be converted to 'Boolean'.
Here is where I added them:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
if(Request.QueryString["r"] != null)
Page.ClientScript.RegisterStartupScript(Me.GetType(), "refresh", "window.setTimeout(window.location.href = '?r=true',3000);", True)
End If
If Not IsPostBack Then
Try
If Not CType(Request.Cookies("Registration")("SignedIn"), Boolean) Then
Yes,it is a boolean one. The page is running well before I add if(Request.QueryString["r"] != null), but it always shows the same error message even I add it to other web pages.
It still has the same problem. There are two errors, for 'Request.QueryString', it says: BC30311: Value of type 'System.Collections.Specialized.NameValueCollection' cannot be converted to 'Boolean',
and for ["r"], the error message marks at " , it says: identifier expected
Sorry now i installed visual studio and tried it. I was working on another laptop. However, The below code shoud work
If Request.QueryString("r") = Nothing Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "refresh", "window.setTimeout('window.location.href = ""?r=true""',3000);", True)
End If
noob08
Member
6 Points
16 Posts
Auto Refresh WebPage Once
Oct 02, 2008 05:43 AM|LINK
Hey, I am new with ASP.NET, and I need helps here. I want to know how to refresh a webpage once. I did some research and I got some VB codes here:
at page_load event
Page.ClientScript.RegisterStartupScript(Me.GetType(), "refresh", "window.setTimeout('var url = window.location.href;window.location.href = url',3000);", True)
but the page will keep refreshing for every few seconds, is there a way to make it just refresh once only??? If this code can't do it, is there any other VB code sample I can use?
Thanks
Haissam
All-Star
37421 Points
5632 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 06:53 AM|LINK
You have to inject this javascript code to the page one time and not everytime the page is executed on the server. This is why you need a variable to indicate that now i want to refresh the page
if(Request.QueryString["r"] != null)
Page.ClientScript.RegisterStartupScript(Me.GetType(), "refresh", "window.setTimeout(window.location.href = '?r=true',3000);", True);
MCAD.NET
| Blog |
noob08
Member
6 Points
16 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 02:58 PM|LINK
Hi Haissam,
Thanks for the reply. The previous codes I have found are actually from your old reply to another topic,[:D] I really appreciate your help. I have added if(Request.QueryString["r"] != null) at my page_load event, but I got error when I run the page, it said: BC30311: Value of type 'System.Collections.Specialized.NameValueCollection' cannot be converted to 'Boolean'.
Here is where I added them:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
if(Request.QueryString["r"] != null)
Page.ClientScript.RegisterStartupScript(Me.GetType(), "refresh", "window.setTimeout(window.location.href = '?r=true',3000);", True)
End If
If Not IsPostBack Then
Try
If Not CType(Request.Cookies("Registration")("SignedIn"), Boolean) Then
Response.Redirect("LogIn.aspx?EM=1&Redirect=" & Request.Url.AbsoluteUri)
Else
Dim strUserID As String = CType(Request.Cookies("Registration")("UserID"), String)
.............................................etc
What can I do to make it work?
Thanks
Haissam
All-Star
37421 Points
5632 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 03:02 PM|LINK
Make sure that the value stored in the cookie is a boolean one.
Request.Cookies("Registration")("SignedIn")
MCAD.NET
| Blog |
noob08
Member
6 Points
16 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 03:14 PM|LINK
Yes,it is a boolean one. The page is running well before I add if(Request.QueryString["r"] != null), but it always shows the same error message even I add it to other web pages.
Haissam
All-Star
37421 Points
5632 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 03:22 PM|LINK
I think it should be
if(Request.QueryString["r"] == null)
And make sure that in first time the page is loading, the cookie exists because you have a problem in converting the value in the cookie to boolean
MCAD.NET
| Blog |
noob08
Member
6 Points
16 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 03:35 PM|LINK
It still has the same problem. There are two errors, for 'Request.QueryString', it says: BC30311: Value of type 'System.Collections.Specialized.NameValueCollection' cannot be converted to 'Boolean',
and for ["r"], the error message marks at " , it says: identifier expected
Haissam
All-Star
37421 Points
5632 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 04:12 PM|LINK
You are using VB.NET and the code supplied is in C# so use the below
If Request.QueryString("r") <> Nothing Then
End If
MCAD.NET
| Blog |
noob08
Member
6 Points
16 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 04:28 PM|LINK
Thanks! Codes could be read now, but the page doesn't auto refresh when page is running.
Haissam
All-Star
37421 Points
5632 Posts
Re: Auto Refresh WebPage Once
Oct 02, 2008 06:08 PM|LINK
Sorry now i installed visual studio and tried it. I was working on another laptop. However, The below code shoud work
If Request.QueryString("r") = Nothing Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "refresh", "window.setTimeout('window.location.href = ""?r=true""',3000);", True)
End If
MCAD.NET
| Blog |