Solved

Automatically refresh page and revert url to previous page in asp

Posted on 2009-04-09
6
601 Views
Last Modified: 2012-05-06
Hi E.E

To explain I have a script ( that i was kindly helped with) that checks the connection to a database, if it's unable to connect it redirects the customer to an error page that does not require a connection. i'd like to refresh the error page say every 10 seconds, and on the refresh go back to the page where the customer previously was, thus running this procedure untill it connects.

a) Would this be the most efficent way of checking that the connection is now available, by posting back to the original page, loading that page if it fails go back to the error page and repeating the process, or by checking the connection on the error page and once it can connect then redirect the url to the customers original page?

b) I use a global.asa, would it be correct to say i need to create a session variable within that, that could grab and store the current page url, so the error page knows where to return to?

This is deeper than im used to so any help is great.
Thanks
0
Comment
Question by:DanielR6
  • 4
  • 2
6 Comments
 
LVL 4

Assisted Solution

by:rentonc
rentonc earned 50 total points
ID: 24107975
Hi DanielR6,

Would you would need to do is use some javascript in the asp page to count down the refresh and send the user to the other page.
You can use the setTimeout() function in Javascript.

Chris
0
 

Author Comment

by:DanielR6
ID: 24108157
Hi again, oh ok, do i still need to setup a session variable storing the customers original page or would javascript cater for that to?

Dan
0
 
LVL 4

Expert Comment

by:rentonc
ID: 24108192
You could simply use querystrings for the original page variable because each of your pages is ASP and can read the querystring collection.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:DanielR6
ID: 24108730
I found this script, which does the refresh job. Though i have no idea how to include the querystring?
 I take it this could be done with session variables though? I only ask as thats something I'd like to play around with.
var refreshinterval=8
var displaycountdown="yes"
var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0
 
function starttime() {
	starttime=new Date()
	starttime=starttime.getTime()
    countdown()
}
 
function countdown() {
	nowtime= new Date()
	nowtime=nowtime.getTime()
	secondssinceloaded=(nowtime-starttime)/1000
	reloadseconds=Math.round(refreshinterval-secondssinceloaded)
	if (refreshinterval>=secondssinceloaded) {
        var timer=setTimeout("countdown()",1000)
		if (displaycountdown=="yes") {
			window.status="Page refreshing in "+reloadseconds+ " seconds"
		}
    }
    else {
        clearTimeout(timer)
		window.location.reload(true)
    } 
}
window.onload=starttime

Open in new window

0
 

Author Comment

by:DanielR6
ID: 24146135
Hi rentonc,

I've been looking at this for sometime now and havn't been able to come up with a fully working solution. So far i have this, but there are some glitches.

I don't know whether it was right to but I added window.history.go(-1) to the else statement to send the page back one step in the history which seems to sort of work, I also changed;  

'Display Error Message to user      
Response.write "An error occurred"
End If

from the pervious piece of code you gave me to ;
'Display Error Message to user
Response.Redirect Server.HTMLEncode("/error_docs/busy.asp")
End If

To send them to the error page if the connection can't be made to the database. The problem I get is that the page on error does go to the error holding page, and the page refreshes untill the connection is available, but when it goes back it seems to jump more than one step back, it goes to the orginal page rather than the page that is trying to be accessed. Im not sure but could it be because if a page gets clicked on, but the connection is down so gets redirected to the holding page it hasn't yet been visited, so its not in the browsers history.

I have also added a session variable to the global.asa if we were able to go down that route.

A bit of assistance on this would be appreciated.

Dan
 
0
 

Accepted Solution

by:
DanielR6 earned 0 total points
ID: 24155790
It seems I now solved it, whether its correct or not im not sure but it works. I was using a response.redirect to transfer the page over to a busy page if the database couldn't connect, however i also created a session variable to store the previous page using HTTP_REFFER. I later found  that the redirect doesnt store in the browser so the reffer can't pick it up, but server.transfer does.

This is the complete code I have. It can probably be much improved on though. Please post improvements if you do.
---------------  global-functions.asp ---------------
 
Place this in an include file for every page that connects to the database;
 
<%
Session("currentpage")= Request.ServerVariables("SCRIPT_NAME")
%>
 
<%
Dim strConnString
Dim db
sub dbconnect(blnswitch)
	Select Case blnswitch
	Case 1
		
		On Error Resume Next
		
                  'Connection name stored in global.asa
		strConnString = Application("ConnName") 
 
		set db = CreateObject("ADODB.Connection")
		
		db.Errors.Clear
		Err.Clear
		db.Open strConnString
		
	Case 0
		db.close
		set db = nothing
	End Select
 
	'Error Handler
	If Err.Number <> 0 Then
            'Clear response buffer
 	    
	Response.Expires = 0 
    Response.Buffer = true 
	Response.Clear
 			
 	    'Redirect the page to the error page
			Server.Transfer("error.asp")
 
 
        End If
 
end sub
%>
 
---------------  global-functions.asp end ---------------
 
---------------  global.asa ---------------
<script language="vbscript" runat="server">
Sub Session_OnStart
	
	'connection string to database
    Application("ConnName") = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Mid(Server.MapPath("\"), 1, InStrRev(Server.MapPath("\"),"\")-1) & "mydatabase.mdb;"
	
End Sub
 
Sub Session_OnEnd
	
End Sub
 
Sub Application_OnStart
 
End Sub
</script>
---------------  global.asa end ---------------
 
---------------  error.asp --------------------
 
This goes on holding page;
 
<script type="text/javascript" />
var refreshinterval=5
var displaycountdown="yes"
var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0
// Name of session stored in 
var n="<%Session("currentpage")%>";
 
 
function starttime() {
	starttime=new Date()
	starttime=starttime.getTime()
    countdown()
}
 
function countdown() {
	nowtime= new Date()
	nowtime=nowtime.getTime()
	secondssinceloaded=(nowtime-starttime)/1000
	reloadseconds=Math.round(refreshinterval-secondssinceloaded)
	if (refreshinterval>=secondssinceloaded) {
        var timer=setTimeout("countdown()",1000)
		if (displaycountdown=="yes") {
			window.status="Page refreshing in "+reloadseconds+ " seconds"
		}
 
    }
    else {
        clearTimeout(timer)
		location.href= (n)
 
    } 
}
window.onload=starttime
 
</script>
---------------  error.asp end -----------------

Open in new window

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question