...

View Full Version : Delaying response.redirect?



DakotaChick
03-21-2006, 09:09 AM
I've set up an asp page that sends an email from the server after the user enters thier comments/name/email into a form. Everything with the CDO Mail works great, the problem comes in when I want to display a message saying thier email was successfully sent. I'd like this page to redirect back to the contact page after a period of ~5 seconds or so. This is the code I currently have:
<%
strName = session("Name")
Response.Write strName & ",<br>"
Response.Write "Your message has been successfully sent."
Response.Redirect("contact.asp")
%>

It redirects immediately, and I'm not sure how to delay it so the user actually has time to see a verification for thier message.

Roelf
03-21-2006, 10:20 AM
Response.Redirecting is only possible if nothing is sent to the client before the command. So you probably have the Response.Buffer set to True. What you can do is output the message and apply the meta tag for redirecting in your messagepage:

<meta http-equiv="Refresh" content="5;url=contact.asp">

DakotaChick
03-21-2006, 10:39 AM
doesnt the meta tag require me to have <html><head></head><html> tags at minimum on the page? The page is pure asp and has no previewable code so to speak. heres the entire page:


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
DIM strEmail, strName, strComments, mail, reply, objMail
strEmail = session("Email")
strName = session("Name")
strComments = session("Comment")

mail = "comments@kaji82.com"
reply = session("Email")
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = reply
objMail.Subject = "New Message From " & strName
objMail.To = mail
objMail.Body = "Email: " & strEmail & vbCrLf & _
"Name: " & strName & vbCrLf & _
"Comments: " & vbCrLf & strComments

objMail.Send
Set objMail = nothing
%>

<P>
<%
strName = session("Name")
Response.Write strName & ",<br>"
Response.Write "Your message has been successfully sent."
Response.Redirect("contact.asp")
%>,</P>

<%
session.Abandon()
%>

Now, what do I need to add to make it display for a few seconds so the user can see that thier message has been sent successfully??

Roelf
03-21-2006, 11:03 AM
you're sending information to a browser, so it is always good practice to send a well formed html document. Including the <html> etc. tags.

degsy
03-21-2006, 03:17 PM
You can use


Response.AddHeader "Refresh", "5;URL=contact.asp"

DakotaChick
03-23-2006, 07:44 AM
You can use


Response.AddHeader "Refresh", "5;URL=contact.asp"

Ah, ty. I knew there had to be a way with out adding in all the uneccessary HTML code to the page. Thank you! :)

Roelf
03-23-2006, 07:58 AM
Yeah, right, unneccesary html code. like <html> etcetera, why do we need that anyway :mad:

DakotaChick
03-23-2006, 08:02 AM
Yeah, right, unneccesary html code. like <html> etcetera, why do we need that anyway :mad:
its not needed on a page that does nothing but process information from one page to another...the user never sees the processing...only a simple msg that says the process compeleted successfully. It would be an utter waste of my time to code in all the html neccessary to simply say "it worked!" and move on to another page...

Roelf
03-23-2006, 08:48 AM
its not needed on a page that does nothing but process information from one page to another...the user never sees the processing...only a simple msg that says the process compeleted successfully. It would be an utter waste of my time to code in all the html neccessary to simply say "it worked!" and move on to another page...
Then why don't you create a good html template, with all neccessary elements in it. A doctype declaration, <html> tags, etcetera. All stuff that is needed to make sure your output is correctly formatted by the browser.
Whenever creating a new asp-page, copy-past the stuff in and add your asp code to make it function the way you want it.
You seem to care about some formatting at least, you "coded" the <P> tag in your output.
Be compliant, it will save you time in the future

DakotaChick
03-23-2006, 09:28 AM
Then why don't you create a good html template, with all neccessary elements in it. A doctype declaration, <html> tags, etcetera. All stuff that is needed to make sure your output is correctly formatted by the browser.
Whenever creating a new asp-page, copy-past the stuff in and add your asp code to make it function the way you want it.
You seem to care about some formatting at least, you "coded" the <P> tag in your output.
Be compliant, it will save you time in the future
every other page (over 85 other pages) is based off of 1 of 2 templates...that page simply sends an email containing the form data...no need for it to look pretty to just say "it worked."

And the copy paste technique went out when dreamweaver and MS offered the option to "create from template."

Instead of arguing with me over the right and wrong way to do things, why not just offer the answer to the question asked and keep the comments to your self? And in the case of not knowing the answer, saying nothing at all? What a novel idea...

Roelf
03-23-2006, 09:54 AM
My apologies if i offended you. Obviously you are right and i am wrong. I will keep comments to myself in the future

degsy
03-23-2006, 03:50 PM
If you are outputting any data to the browser then it should be correctly formed.

You never know what browser or OS / Device is being used to view your pages and maybe there is a strict browser out there that will refuse to display your page if there is no DOCTYPE, HEAD or BODY.

Roelf
03-23-2006, 03:59 PM
If you are outputting any data to the browser then it should be correctly formed.

You never know what browser or OS / Device is being used to view your pages and maybe there is a strict browser out there that will refuse to display your page if there is no DOCTYPE, HEAD or BODY.
I agree completely, that is why i mentioned it. But DakotaChick seems to think of it in other ways

DakotaChick
03-24-2006, 04:24 PM
it was for testing phases more than actual use. there is a showif statement now on the contact page (which is a highly structured html/asp/vbscript page) that tells the user if everything went correctly. I just dont like all the extraneous coding during testing on my pc.

miranda
03-25-2006, 05:50 PM
As an aside, Response.Buffer is set to true by default beginning with IIS 5



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum