A.G.
A.G.

Reputation: 2149

Redirect aspx to new page but with message and wait?

I want to redirect to a new page, but I'd like to show a message and have a small waiting period so users can read it:

I know I can do this:

<script runat="server">
 protected override void OnLoad(EventArgs e)
  {
  Response.Redirect("new.aspx");
  base.OnLoad(e);
  }
 </script>

But How can I show the message and wait?

Thanks.

Upvotes: 0

Views: 2623

Answers (4)

Ewerton
Ewerton

Reputation: 4523

you can pass the message and the time to wait in query string

Response.Redirect("new.aspx?Message=Your_Message&Time=3000")

in the Page_Load of new.aspx you can catch the parameters

string msg = Request["Message"]
string time = Request["Time"]

You need the user wait x seconds to see the message? if yes, you will need to do it by javascript.

First, create a javascript function to show the message

function ShowMessage(msg) {
        alert(msg);
    }

then, in code behind of the new.aspx, get the parameters and call the javascript function

protected void Page_Load(object sender, EventArgs e)
    {
        string msg = Request["Message"].ToString();
        string tempo = Request["Time"].ToString();
        string script = String.Format(@"setTimeout(""ShowMessage('{0}')"", {1})", msg, tempo);
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "key", script, true);
    }

It will show the message after 3 seconds.

Upvotes: 0

Erwin
Erwin

Reputation: 4817

Instead of using server-side code, you can do it in html, with meta refresh:

<html>
 <head>
  <title> Redirect </title>
  <meta http-equiv="refresh" content="60;URL='http://foo/new.aspx'"/>
 </head>

 <body>
    <p>You will be redirected in 60 seconds</p>
 </body>
</html>

You can change 60 in the content attribute of the meta tag into the seconds you want the user to wait.

Upvotes: 2

tristankoffee
tristankoffee

Reputation: 670

Have you tried using a meta refresh tag?

Documentation can be found here: http://en.wikipedia.org/wiki/Meta_refresh

Basically, you put a meta refresh tag in the <head/> section of your HTML and specify a wait time along with a URL.

e.g.

<meta http-equiv="refresh" content="15;URL='http://www.something.com/page2.html'">

In the above example, the page will wait 15 seconds, and then redirect to http://www.something.com/page2.html.

So, you could create a page with your message on it, and put a meta refresh in the header of it. After the set period of time, it will "refresh" to new.aspx.

e.g.

<html>
  <head>
    <title>Redirecting</title>
    <meta http-equiv="refresh" content="15;URL='new.aspx'">
  </head>
  <body>
    <p>Thanks for visiting our site, you're about to be redirect to our next page.  In the meantime, here's an interesting fact....</p>
  </body>
</html>

Upvotes: 0

Dmitry Vasiliev
Dmitry Vasiliev

Reputation: 93

You can use client-side technology, meta tag for example

<HTML>
<HEAD>
<!-- Send users to the new location. -->
<TITLE>redirect</TITLE>
<META HTTP-EQUIV="refresh" 
CONTENT="10;URL=http://<URL>">
</HEAD>
<BODY>
[Your message here]
</BODY>
</HTML>

Upvotes: 0

Related Questions