views:

6733

answers:

4

What is the code required to redirect the broweser to a new page with an ASPX page?

I have tried this on my page default.aspx :

<% Response.Redirect("new.aspx", true); %>

or

<%@ Response.Redirect("new.aspx", true); %>

And these result in a server error that is undetermined. I cannot see the error code because the server is not in my control and the errors are not public.

Please provide all necessary code from line 1 of the page to the end, and I would really appreciate it.

+10  A: 
<%@ Page Language="C#" %>
<script runat="server">
  protected override void OnLoad(EventArgs e)
  {
      Response.Redirect("new.aspx");
      base.OnLoad(e);
  }
</script>
Darin Dimitrov
works perfectly thanks
Stoob
+1  A: 

If you are using VB, you need to drop the semicolon:

<% Response.Redirect("new.aspx", true) %>
wweicker
+2  A: 

You could also do this is plain in html with a meta tag:

<html>
<head>
  <meta http-equiv="refresh" content="0;url=new.aspx" />
</head>
<body>
</body>
</html>
jrummell
Why the down vote?
jrummell
Seriously, what's with the down votes? If all that you need to use is redirect to another page, you don't have to use ASP.Net. If you need to drive a nail and you could choose between a normal hammer and sledge hammer, which would you choose? I hope you'd say the normal hammer.
jrummell
I vote jackhammer. Pneumatic is the only way to fly.
Wyatt Barnett
This was an html solution to an asp.net problem.
Daniel A. White
Right, but html is a HUGE part of ASP.NET.
jrummell
cut the guy some slack, i gave you a positive just for being nice. this is a good backup way of doing it if the first ASP.NET option hadn't worked.
Stoob
Thanks for the up vote. I didn't mean to offend anyone. I just wanted to point out that you don't need server side scripting to redirect.
jrummell
in this case i did need to do it server side, otherwise the HTML would have worked fine
Stoob
+1  A: 

Even if you don't control the server, you can still see the error messages by adding the following line to the Web.config file in your project (bewlow <system.web>):

<customErrors mode="off" />
SLaks