Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Redirect user with ASP code in <body> ?

Reply
Thread Tools

Redirect user with ASP code in <body> ?

 
 
Noozer
Guest
Posts: n/a
 
      07-25-2005
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.REDIRECT "url" won't work.

Any suggestions?



 
Reply With Quote
 
 
 
 
Roji. P. Thomas
Guest
Posts: n/a
 
      07-25-2005
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" <(E-Mail Removed)> wrote in message
news:e51Fe.35518$s54.13194@pd7tw2no...
> 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.REDIRECT "url" won't work.
>
> Any suggestions?
>
>
>



 
Reply With Quote
 
 
 
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-25-2005
> 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.redirect "place"
else
response.write "stuff"
end if
%>

> - so RESPONSE.REDIRECT "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>location.replace('place');</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


 
Reply With Quote
 
Noozer
Guest
Posts: n/a
 
      07-25-2005
> Yes, if you can't use more sensible logic on the server side, use
> client-side script.
>
> <% if mySum > 10 then %>
> <script>location.replace('place');</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("Entry" & i)="" then
Response.Redirect "EntryPage.asp"
end if
Response.Write "You entered " & request.form("Entry"&i) & " for #" & i &
".<br />" & vbcrlf
next i
%>
Done!<br />


 
Reply With Quote
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-25-2005
> Your entries:<br />
> <%
> for i = 1 to 20
> if Request.Form("Entry" & i)="" then
> Response.Redirect "EntryPage.asp"
> end if
> Response.Write "You entered " & request.form("Entry"&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("Entry" & i)
if e = "" then
response.redirect "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 ****ed 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


 
Reply With Quote
 
Noozer
Guest
Posts: n/a
 
      07-26-2005
It was an over simplified example... It's actually querying a database
etc...

"Aaron Bertrand [SQL Server MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> Your entries:<br />
>> <%
>> for i = 1 to 20
>> if Request.Form("Entry" & i)="" then
>> Response.Redirect "EntryPage.asp"
>> end if
>> Response.Write "You entered " & request.form("Entry"&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("Entry" & i)
> if e = "" then
> response.redirect "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 ****ed 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
>



 
Reply With Quote
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-26-2005
> It was an over simplified example... It's actually querying a database
> etc...


And...? How does that change anything?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Response.redirect does not redirect from .aspx page =?Utf-8?B?VHJveQ==?= ASP .Net 3 10-15-2008 09:07 PM
redirect specefic user with specefic role to specefic pages ASP.ne SemSem ASP General 1 02-05-2007 07:55 AM
global filter to redirect asp (old asp!) pages on asp.net site Daves ASP .Net 2 05-31-2006 08:33 AM
Redirect to secure FTP site via response.redirect Ron Howard ASP General 2 08-11-2004 07:40 PM
Basic Q - Response.Redirect, all redirect to first Response.Redirect statement Sal ASP .Net Web Controls 1 05-15-2004 03:46 PM



Advertisments