473,509 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correct way to use Response Redirect in .NET

Hello, I have an old asp page that was used to redirect users called
redirect.asp:

<code1>
<%
Option Explicit

If Request.QueryString("url") <> "" Then
Response.Redirect Request.QueryString("url")
Else
Response.Redirect ("www.examplesite.asp")
End If
%>
</code1>
So far I have this:

<code2>
<%@ Page Language="vb" enableviewstate="False"%>
<script runat=server>
Public Sub Page_Load()
Response.Redirect ("http://www.tv.dlpsaleslab.com/default.aspx")
End Sub
</script>
</code2>

My question is how do I use VB.NET to do this.
When I add the above code I am given an error, since I am new to VB,
can someone help advise what is the proper way to set up a
Response.Redirect in the manner as I have done in in code1 using
VB.NET?

Thank you,
Jul 21 '05 #1
8 3177
The need for Response.Redirect is greatly diminished in .NET. Look into
Page.IsPostBack.
"Daniel" <te**********@yahoo.com> wrote in message
news:78**************************@posting.google.c om...
Hello, I have an old asp page that was used to redirect users called
redirect.asp:

<code1>
<%
Option Explicit

If Request.QueryString("url") <> "" Then
Response.Redirect Request.QueryString("url")
Else
Response.Redirect ("www.examplesite.asp")
End If
%>
</code1>
So far I have this:

<code2>
<%@ Page Language="vb" enableviewstate="False"%>
<script runat=server>
Public Sub Page_Load()
Response.Redirect ("http://www.tv.dlpsaleslab.com/default.aspx")
End Sub
</script>
</code2>

My question is how do I use VB.NET to do this.
When I add the above code I am given an error, since I am new to VB,
can someone help advise what is the proper way to set up a
Response.Redirect in the manner as I have done in in code1 using
VB.NET?

Thank you,

Jul 21 '05 #2
So to clarify, how to I use Page.IsPostBack in this manner to accomplish
the same as I have done in the first bit of code?

Any help would be appreciated?

Thanks,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3
Here is a brief explanation of how and when to use...

Response.Redirect functions in ASP.NET exactly as it did in ASP
as the intrinsic ASP objects have been carried over to ASP.NET
for backward compatibility.

Using Response.Redirect requires two trips to the server and imposes
performance penalties and should only be used when the three
following circumstances demand its use...

1.) When redirecting to a remote server.
2.) When redirecting to a different website on the same server.
3.) When redirecting to static pages, i.e. from .asp to .htm, .aspx to .htm
or to pages generated by different application servers such as .asp to .php
and .aspx to .php.

Otherwise use the Server.Transfer method or Server.Execute as the
circumstances may require.

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Terry Ashley" <te**********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
So to clarify, how to I use Page.IsPostBack in this manner to accomplish
the same as I have done in the first bit of code?

Any help would be appreciated?

Thanks,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #4
It looks like you were trying to see if the page had ever been loaded before
(if it had, there would be a querystring value). So, in .NET we'd do:

If IsPostBack Then
Response.Redirect Request.QueryString("url")
Else
Response.Redirect ("www.examplesite.asp")
End If

Using Redirect only in circumstances previously posted.

"Terry Ashley" <te**********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
So to clarify, how to I use Page.IsPostBack in this manner to accomplish
the same as I have done in the first bit of code?

Any help would be appreciated?

Thanks,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #5
So since i am doing both 2,3 here using Response.Redirect is the right
way to go.

So in fact this seems to work, but as far as using ASP.NET correctly is
this the proper way to format it, if so thank you very much.

<%@ Page Language="vb" enableviewstate="False"%>
<script runat="server">
Public Sub Page_Load()

If Request.QueryString("url") <> "" Then
Response.Redirect Request.QueryString("url")
Else
Response.Redirect ("http://www.example/default.aspx")
End If

End Sub
</script>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #6

Thanks for the correction, however when I link to this file from another
page, I get an error:

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: BC30800: Method arguments must be enclosed in
parentheses.

Source Error:
Line 4:
Line 5: If IsPostBack Then
Line 6: Response.Redirect Request.QueryString("url")
Line 7: Else
Line 8: Response.Redirect
("http://www.example.com/default.aspx")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #7
Thanks for your help the following code seems to achive what I am
looking for.

<code>

<%@ Page Language="vb" enableviewstate="False"%>
<script runat="server">
Public Sub Page_Load()

If IsPostBack Then
Response.Redirect (Request.QueryString("url"))
Else
Response.Redirect ("http://www.example.com/default.aspx")
End If

End Sub
</script>

</code>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #8
It just means that in .NET, you must pass method arguments in parenthesis.
Your first redirect doesn't have any parenthesis. Try this:
If IsPostBack Then
Response.Redirect(Request.QueryString("url"))
Else
Response.Redirect("http://www.example.com/default.aspx")
End If

"Terry Ashley" <te**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

Thanks for the correction, however when I link to this file from another
page, I get an error:

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: BC30800: Method arguments must be enclosed in
parentheses.

Source Error:
Line 4:
Line 5: If IsPostBack Then
Line 6: Response.Redirect Request.QueryString("url")
Line 7: Else
Line 8: Response.Redirect
("http://www.example.com/default.aspx")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #9

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

Similar topics

3
3886
by: Paul | last post by:
I'm not getting the results I want when I use Response.Redirct in a ASP page. I enter this line of code in a asp page from domain1.com. Response.Redirect...
4
14595
by: TomT | last post by:
Hi.. I'm redirecting users to another page using: response.redirect("newpage.asp") this works... But I need to add a variable to the page specified.. IE: newpage.asp?id=JobID
6
4300
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
2
1440
by: darrel | last post by:
I've been struggling with a page that is set up like this: PAGE: ------------------ control 1 - reads a cookie and executes stuff based on that control 2 - reads the same cookie and can also...
8
340
by: Daniel | last post by:
Hello, I have an old asp page that was used to redirect users called redirect.asp: <code1> <% Option Explicit If Request.QueryString("url") <> "" Then Response.Redirect ...
1
1789
by: stevebremermn | last post by:
I'm working on setting up some affiliate links on a site of mine and I haven't been able to get a redirect to work. The original affiliate link looks like this: ...
5
4546
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
4
11387
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
1
1744
by: Culley | last post by:
I've created a secure login site. Everything works fine except for one thing... the redirect. I want to redirect users to the correct page they are accessing (say they're just clicking a link...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
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...
0
7347
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,...
0
7416
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...
0
7506
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...
0
4732
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...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
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 ...

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.