在执行Response.redirect之前显示消息 [英] Show message BEFORE doing Response.redirect

查看:81
本文介绍了在执行Response.redirect之前显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在执行响应之前,尝试显示一条消息(从服务器端到客户端)时遇到麻烦.重定向到另一个页面.
关键是我放了代码来显示消息,但它从未出现在页面中,它进行了重定向,但没有显示消息.

我用来显示消息的代码是这样的:

Hi,
I''m having trouble trying to show a message (from the server side to the client side) before I do a response.redirect to another page.
The thing is that I put the code to show the message but it never appears in the page, it does the redirect but it doesn''t show the message.

The code I''m using to show the message is this:

sScript.AppendLine("<script type=""text/javascript"">")
sScript.AppendLine("  alert('La operacion no ha sido exitosa');")
sScript.AppendLine("</script>")
ScriptManager.RegisterStartupScript(Me, Me.GetType, "AlertaJS", sScript.ToString, False)



sScript是一个字符串生成器



还有其他方法可以显示从服务器端到客户端的消息吗?



sScript is a stringbuilder



Is there any other way to showing messages from server side to client side?

Thanks!

推荐答案

当您使用Response.Redirect时,ASP.NET会添加标头来发布302,对象已移动.由于浏览器处理标头并请求新的url,因此在页面实际加载之前,此方法对您不起作用.

您可以在警报后添加JavaScript,例如

When you use a Response.Redirect ASP.NET adds header to issue a 302, object moved. Since the browser processes the header, and requests the new url, before the page actually loads this method won''t work for you.

You can add JavaScript after the alert such as

window.location.href = ''http://my new location'';


Sheerim,
在Response.Redirect之前显示消息 [
Hi Sheerim,
Show Message Before Response.Redirect[^]
I hope it helps you.


将您的消息放在带有此标头的页面中:
place your message in a page with this header :
<meta http-equiv="refresh" content="5;url=Default.aspx" />

并将它们重定向到此页面.
此标头将在5秒后将它们重定向到"default.aspx",但在此之前它们可以看到您的消息.

例子:

and redirect them to this page.
This header will redirect them to the "default.aspx" after 5 seconds but before that they can see your message.

example :

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Access Denied</title>
    <meta http-equiv="refresh" content="5;url=Default.aspx" />
    <link rel="Stylesheet" type="text/css" href="default.css" />
</head>
<body dir="rtl">
    <form id="form1" runat="server">
    <div class="error">
        <img alt="error" src="images\cross1.png" width=50 height=50 />
       access denied.</div>
        <br />
        <br />
        <a href="Default.aspx">go to home page</a>


    </form>
</body>


这篇关于在执行Response.redirect之前显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆