【问题标题】:Redirect aspx to new page but with message and wait?将aspx重定向到新页面但带有消息并等待?
【发布时间】:2012-09-23 09:53:05
【问题描述】:

我想重定向到一个新页面,但我想显示一条消息并等待一小段时间以便用户阅读:

我知道我可以做到:

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

但是我怎样才能显示消息并等待呢?

谢谢。

【问题讨论】:

    标签: asp.net redirect message


    【解决方案1】:

    您可以在 html 中使用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>
    

    您可以将meta 标记的content 属性中的60 更改为您希望用户等待的秒数。

    【讨论】:

      【解决方案2】:

      您可以使用客户端技术,例如元标记

      <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>
      

      【讨论】:

        【解决方案3】:

        您是否尝试过使用元刷新标签?

        文档可以在这里找到:http://en.wikipedia.org/wiki/Meta_refresh

        基本上,您在 HTML 的 &lt;head/&gt; 部分放置一个元刷新标签,并指定一个等待时间和一个 URL。

        例如

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

        在上面的例子中,页面会等待 15 秒,然后重定向到http://www.something.com/page2.html

        因此,您可以创建一个包含您的消息的页面,并在其标题中放置一个元刷新。在设定的时间后,它会“刷新”到new.aspx。

        例如

        <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>
        

        【讨论】:

          【解决方案4】:

          您可以在查询字符串中传递消息和等待时间

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

          在new.aspx的Page_Load中可以捕捉参数

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

          您需要用户等待 x 秒才能看到消息吗? 如果是,则需要通过 javascript 来完成。

          首先,创建一个 javascript 函数来显示消息

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

          然后,在new.aspx后面的代码中,获取参数并调用javascript函数

          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);
              }
          

          它将在 3 秒后显示消息。

          【讨论】:

            猜你喜欢
            • 2010-11-08
            • 2012-08-12
            • 1970-01-01
            • 2015-03-02
            • 1970-01-01
            • 1970-01-01
            • 2013-01-15
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多