method,great,moving,user,from,page,another,Ho
Quick Search for:  in language:    
method,great,moving,user,from,page,another,Ho
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 132,008 lines
 Jobs: 198 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
if i remember, this is a M. Harris code sample
By ask on 8/24


MTS Registration Script
By Igor Krupitsky on 8/23


Click here to see a screenshot of this code!Creating Windows Users with ASP and ADSI
By jamespwalters on 8/23

(Screen Shot)

News Poster (Advanced)
By Martin Kilbryde on 8/22


Print a web document through MS Word
By ask on 8/22


Click here to see a screenshot of this code!ADSI Domain Group Explorer
By Gordon Asbach on 8/22

(Screen Shot)

_-~Who is looking at your site? v2.0!~-_
By John on 8/22


Using HTML Option to Display Current Month
By Patrick Ingle on 8/20


FdB: Free Database (Aka Fake Database)
By TV2k.net on 8/19


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

A better response.redirect

Print
Email
 
VB icon
Submitted on: 2/14/2000
By: Ian Ippolito (psc)  
Level: Intermediate
User Rating: By 13 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 31019 times.
 

(About the author)
 
     The response.redirect method is great for moving a user from one page to another. However, it does have one major limitation--you can only use it if absolutely nothing has been written to the page. Sometimes, you actually do want to write something to the page and then redirect it, for example when displaying the status of an operation. In this case, the following JavaRedirect function comes in handy. It requires a Java compatible browser. (Note:this script has been changed to incorporate Lewis Moten's helpful suggestions).
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: A better response.redirect
    ' Description:The response.redirect meth
    '     od is great for moving a user from one p
    '     age to another. However, it does have on
    '     e major limitation--you can only use it 
    '     if absolutely nothing has been written t
    '     o the page. Sometimes, you actually do w
    '     ant to write something to the page and t
    '     hen redirect it, for example when displa
    '     ying the status of an operation. In this
    '     case, the following JavaRedirect functio
    '     n comes in handy. It requires a Java com
    '     patible browser. (Note:this script has b
    '     een changed to incorporate Lewis Moten's
    '     helpful suggestions).
    ' By: Ian Ippolito (psc)
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/xq/ASP/txtCode
    '     Id.0/lngWId.4/qx/vb/scripts/ShowCode.htm    'for details.    '**************************************
    
    Sub JavaRedirect (strURL)
    'Response.Write "redirect to:" & strURL
    %>
    <SCRIPT language="JavaScript">
    <!--
    window.location.href = 
    '<%=URL%>';
    //-->
    </SCRIPT>
    <%
    End Sub


Other 34 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
4/21/2000 8:19:55 AM:cpsarros
Excellent simplicity 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/3/2000 11:55:28 AM:Tony
Err... It would be much easier to set 
the following line 
server-side:<R0Response.Buffer = True 
êdd this to the top of your ASP page 
and you can redirect AFTER the client 
headers are written. There is no need 
to rely on a client-side script.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/3/2000 12:10:37 PM:Tony
Response.Buffer = True
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/5/2000 12:12:34 PM:Ian Ippolito
Tony,
   I appreciate the feedback 
but doing response.buffer = true 
doesn't quite do the same thing.  If 
you use that method, the redirect will 
succeed, but you won't actually see the 
text that was output to the screen 
before hand.  That won't work for the 
'status' situation described.
Ian
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/17/2000 7:52:32 AM:serkan
this is so cool. thnx.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/21/2000 12:32:00 PM:Lewis Moten
If you want to let users see content 
before redirecting them, you can always 
use META tags to refresh the page to 
another URL after a specified amount of 
time.  More browsers would be 
compatable with this method.  Your code 
doesn't even use timers to give the 
users time to see what you have 
written.
Also, your javascript is in 
a vbScript format.  
1. javascript is 
case sensitive
2. javascript uses {} 
to define content within if 
comparisons.
this will definately 
crash your browsers.  here is the real 
deal.
<SCRIPT 
language="JavaScript">
<!--
window.loc
ation.href = 
'<%=URL%>';
//-->
</SCRIPT>
There 
is no need to test for netscape 
browsers by doing it this way.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/21/2000 4:45:28 PM:Ian Ippolito
Lewis,
 Thanks for the feedback, but 
the META tag method only works if you 
know in advance how long the operation 
is going to take, and alot of times you 
don't.  For example on Planet Source 
Code, I use the above script when an 
author submits code so I can display a 
status.  I can't predict in advance how 
long the upload will take, because each 
upoad is a different size and each user 
has a different speed 
connection.
Regarding {} to wrap 
comparisons--I've never read any 
Javascript book describing this as a 
legal way to do 
comparisons.
However, I do like your 
final one line solution.  I don't know 
why I originally did the trap for 
Netscape that way (this is kind of old 
code...)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/22/2000 4:36:34 PM:Lewis Moten
Cool.  Another approach would be to 
have a function called after the page 
completly loads <BODY 
onLoad="nextPage()">.  then the 
function would call a timer to change 
the location after the user has some 
time to read the page.  There are many 
different approaches to this situation. 
 I was just unaware of the specific 
requirements. I usually use the {} tags 
just about everywhere so that i can 
stay away from any possible errors that 
may arise in different versions of 
javaScript.  thanks for the reply.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/3/2000 1:13:25 PM:Merlyn
You can use the Response.Redirect even 
if you have written to the page by 
using Response.Buffer = True  in this 
case all data to the page is buffered 
until the page is processed or you 
force the contents of the buffer to the 
page.  
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/7/2000 12:58:20 PM:Ian Ippolito
Merlyn,
Thanks for the 
feedback...but this is the same thing 
Tony said above.   See the response to 
his message...
Ian
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/19/2001 4:30:07 PM:Mike Wees
Ian,
I have a question related to 
this, I couldn't find it answered 
anywhere else.  I'm trying to program a 
GoBack routine.  I want to emulate the 
user pressing the Back button on the 
browser so that all the form values are 
retained.  Any idea on the code for 
this?  Thanks in advance.
MW
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/16/2001 11:18:38 AM:John Tolar
Actully, the last question had nothing 
to do with the topic or code. But, try 
history.Back();
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/18/2002 2:37:29 PM:Imvain
For comparison to the Javascript 
solution.
Im kind partial to the 
location.replace(); function.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/19/2002 11:29:46 AM:A1 Programmer
If the user Presses the [ Back ] Button 
on the browser, the form values will be 
Retained, but anyway...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/19/2002 11:30:55 AM:a1 programmer
<kbd>
<a 
href="Javascript:history.back()">Back</a
>
or
<a 
href="javascript:history.go(-1)">Back</a
>
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/4/2002 11:20:03 PM:Sam Moses
good stuff. This approach never 
occurred to me. Thanks for the insight.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/16/2002 11:42:44 AM:xmetrix@aol.com
response.buffer=true
response.flush
re
sponse.redirect(
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/16/2002 12:36:13 PM:Ian Ippolito (psc)
Thanks xmetrix, but like the others, it 
still doesn't help with the situation 
described above "Sometimes, you 
actually do want to write something to 
the page and then redirect it".  The 
code you put up would never display 
anything.
Ian
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.