473,836 Members | 1,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redirect user with ASP code in <body> ?

Is it possible to redirect a user to another web page using ASP code located
in page body?

I have some ASP code that runs after generating some output to the browser.
It checks for a condition that can only be calculated using the values
produced in the output, so redirecting the user before the <html> tag isn't
possible without running the code twice (which I'd like to avoid.) - so
RESPONSE.REDIRE CT "url" won't work.

Any suggestions?

Jul 25 '05 #1
7 1924
Set Response.Buffer = true

Then you will be able to redirect before flushing the buffer output to the
client.

--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Noozer" <do*******@me.h ere> wrote in message
news:e51Fe.3551 8$s54.13194@pd7 tw2no...
Is it possible to redirect a user to another web page using ASP code
located
in page body?

I have some ASP code that runs after generating some output to the
browser.
It checks for a condition that can only be calculated using the values
produced in the output, so redirecting the user before the <html> tag
isn't
possible without running the code twice (which I'd like to avoid.) - so
RESPONSE.REDIRE CT "url" won't work.

Any suggestions?

Jul 25 '05 #2
> It checks for a condition that can only be calculated using the values
produced in the output
I don't understand why there has to be any HTML output before these values
are produced.
, so redirecting the user before the <html> tag isn't
possible without running the code twice (which I'd like to avoid.)
Why do you have to run any code twice?

Instead of saying:

<%=x+y%>

Just say:

<%
mySum = x + y
%>

Then later you can say,

<%
if mySum > 10 then
response.redire ct "place"
else
response.write "stuff"
end if
%>
- so RESPONSE.REDIRE CT "url" won't work.

Any suggestions?


Yes, if you can't use more sensible logic on the server side, use
client-side script.

<% if mySum > 10 then %>
<script>locatio n.replace('plac e');</script>
<% end if %>

Now you don't have to alter the buffering behavior of the page, or fight
with the server's settings, etc. I still don't understand why ASP script
would ever have to be run twice...

http://www.aspfaq.com/2262
http://www.aspfaq.com/2011
http://www.aspfaq.com/2217
Jul 25 '05 #3
> Yes, if you can't use more sensible logic on the server side, use
client-side script.

<% if mySum > 10 then %>
<script>locatio n.replace('plac e');</script>
<% end if %>

Now you don't have to alter the buffering behavior of the page, or fight
with the server's settings, etc. I still don't understand why ASP script
would ever have to be run twice...


Your entries:<br />
<%
for i = 1 to 20
if Request.Form("E ntry" & i)="" then
Response.Redire ct "EntryPage. asp"
end if
Response.Write "You entered " & request.form("E ntry"&i) & " for #" & i &
".<br />" & vbcrlf
next i
%>
Done!<br />
Jul 25 '05 #4
> Your entries:<br />
<%
for i = 1 to 20
if Request.Form("E ntry" & i)="" then
Response.Redire ct "EntryPage. asp"
end if
Response.Write "You entered " & request.form("E ntry"&i) & " for #" & i &
".<br />" & vbcrlf
next i
%>
Done!<br />


How about:

<%
for i = 1 to 20
line = "You entered _e_ for #_i_.<br />" & vbcrlf

e = Request.Form("E ntry" & i)
if e = "" then
response.redire ct "EntryPage. asp"
response.end
else
output = output & replace(replace (line, "_e_", e),"_i_",i)
end if
next

response.write output
%>

My main question, I guess re-worded, is, "why bother writing out 19 lines
the user won't have time to see, if they didn't fill out the 20th entry?"
And that leads to another question, why let them submit the form at all, if
they are going to have to go back and start over? It seems you need to
learn a little bit about usability... I would be pissed if you let me fill
out 19 items, then sent me back to an empty form because you didn't bother
*forcing* me to fill out the 20th item.

A
Jul 25 '05 #5
It was an over simplified example... It's actually querying a database
etc...

"Aaron Bertrand [SQL Server MVP]" <te*****@dnartr eb.noraa> wrote in message
news:uY******** ******@TK2MSFTN GP12.phx.gbl...
Your entries:<br />
<%
for i = 1 to 20
if Request.Form("E ntry" & i)="" then
Response.Redire ct "EntryPage. asp"
end if
Response.Write "You entered " & request.form("E ntry"&i) & " for #" & i &
".<br />" & vbcrlf
next i
%>
Done!<br />


How about:

<%
for i = 1 to 20
line = "You entered _e_ for #_i_.<br />" & vbcrlf

e = Request.Form("E ntry" & i)
if e = "" then
response.redire ct "EntryPage. asp"
response.end
else
output = output & replace(replace (line, "_e_", e),"_i_",i)
end if
next

response.write output
%>

My main question, I guess re-worded, is, "why bother writing out 19 lines
the user won't have time to see, if they didn't fill out the 20th entry?"
And that leads to another question, why let them submit the form at all,
if they are going to have to go back and start over? It seems you need to
learn a little bit about usability... I would be pissed if you let me fill
out 19 items, then sent me back to an empty form because you didn't bother
*forcing* me to fill out the 20th item.

A

Jul 26 '05 #6
> It was an over simplified example... It's actually querying a database
etc...


And...? How does that change anything?
Jul 26 '05 #7

this sort of thing comes up a lot w/ logins...you can't really avoid
redirecting in the middle of the code sometimes (or you can, but
sometimes it's sloppy, imo).

I like the response.flush deal the most. But sometimes that's not going
to work -- like in this board w/ the search, how it says
"searching...cl ick here to contine" you can't use a response.redire ct
(well you can, it's just messy since you're outputting
javascript...et c...blah...diff erent topic). Instead output a bit of
javascript: document.locati on = "askfhsd".

PHP is nortorious for being a pain about redirects too...especiall y on
windows....so i use the javascript all the time w/ php.

--
garraeth
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jul 29 '05 #8

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

Similar topics

0
2166
by: Andrés Giraldo | last post by:
Hi! It's possible to register some script between the <head> and </head> actually I'm Using RegisterStartupScript and RegisterClientBlockScript, but it works on the body By the way... how can I add an attribute to the <BODY> ? I need to assign a function on the onLoad attribute of the body... how
1
2147
by: Gordon - Adelphia | last post by:
I have a question regarding xhtml. Why, why, why does the ELEMENT <body> allow “unblocked” text. HTML does not (though, most browsers will render). Xhtml (transitional) however allows text nodes (PCDATA). All of HTML 4, xhtml – transitional, and xhtml-strict allow <div> to contain “unblocked” text. Does anybody know why – I’m looking for the philosophy behind allowing such. I’m in the process of encapsulating xhtml mark-up in content...
2
1502
by: Starry Gordon | last post by:
I've been running some small test programs which seem to indicate something noticed in a larger script, that a function called from onLoad() in the <body> tag will not succeed in creating a window (i.e. successfully executing window.open() in Mozilla 1.5; however, I've observed it to work a few times in IE 6.0 and Opera 5.something. It does not seem to be a timing thing -- if I re-call the function somewhat later using setTimeout it still...
1
3069
by: Dung Ping | last post by:
For instance, one set is: <body onload="blinking_header()" onunload="stoptimer()"> Another set is: <body onload="writemsg()" onunload="stoptimer()"> They represent two functions. How to place them in the <body> tag? Thanks.
3
2308
by: francescomoi | last post by:
Hi. I'm trying to insert some text between <head> and <body> but I'm not able. I try with: -------- bodyPoint = document.getElementsByTagName('body'); var myLink = document.createElement("a");
15
2259
by: Frances | last post by:
<html> <head> <script> function doIt() { var list = document.forms.product; var selItem = list.options.value; ^^^^^^^ </head>
5
11046
by: Rick Spiewak | last post by:
I need to generate a "buy" button as part of an ASP.NET page - this consists of a small HTML form with hidden fields, conforming to the requirements of a merchant credit card processor. PayPal is similar. I'm succeeding in doing this by using Writer.Write to emit my HTML, at least as far as getting it to work. However, depending on where I put MyBase.Render(Writer), I get my HTML either before the header or after the end of the body of...
12
4936
by: Mark Rae | last post by:
Hi, It's easy enough for a child page to manipulate its MasterPage's header simply by modifying the MasterPage thus: <header runat="server"> .... .... </header>
23
2248
by: Xah | last post by:
Here's a interesting case of invalid html 4 strict file. In summary, if you have <body></bodywithout any content, the file would be invalid under html 4 strict. Valid if html 4 lose. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/ TR/html4/strict.dtd"> <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=utf-8">
0
9671
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10549
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4456
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.