Response.Write和Response.Redirect [英] Response.Write and Response.Redirect

查看:135
本文介绍了Response.Write和Response.Redirect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的活动中,我需要做一些验证然后让

继续,或者显示错误信息并将它们重新启动回

上一页。以下是代码:

On my event, i need to do some validation and then either let
them proceed, or display a error message and boot them back to the
previous page. Here is the code:

Response.Write("<script>alert('Error Message here');</script>");
Response.Redirect("Configuration.aspx");



问题是,如果我调用Response.Redirect将它们移动到之前的

页面,则Response.Write会被吃掉。我如何解决这个问题?

谢谢!


Problem is that if I call Response.Redirect to move them to the previous
page, the Response.Write gets eaten. How do I solve this issue?
thanks!

推荐答案

我不知道你为什么使用response.redirect()?



尝试使用,



I don''t know why are you using response.redirect()?

Try to use,

Page.ClientScript.RegisterStartupScript(Page.GetType(), "my", "alert("Error message");", true)
Response.Redirect("Configuration.aspx",false);





如果您还有其他问题,请告诉我。



If you have any further problem, So please let me know.


您好,



在将任何标头/数据发送到客户端之前,应使用Response.Redirect。将忽略任何响应正文内容,例如原始URL指示的页面中显示的HTML文本或Response.Write文本。此外,当处理Redirect方法时,终止当前页面中的代码执行,因此页面中的后续代码也将被忽略。如果你真的想显示错误信息,那么你可以这样做

Hello,

Response.Redirect should be used before sending any headers/data to the client. Any response body content such as displayed HTML text or Response.Write text in the page indicated by the original URL is ignored. In addition, code execution in the current page is terminated when the Redirect method is processed, so subsequent code in the page will also be ignored. If you really really want to display the error message then you can do it


  1. 将错误信息存储在会话中,并将密钥作为页面名称( Configuration.aspx)以及Configuration.aspx运行时显示它并将其从会话中删除
  2. 发送包含javascript的响应,该响应将显示错误并使用

  1. Store the error message in session with key as the page name (Configuration.aspx) and when the Configuration.aspx runs display it and remove it from session as well
  2. Send a response containing javascript which will show the error and use
location.replace(newURL)

将用户发送到Configuration.aspx。

to send user to Configuration.aspx.





问候,



Regards,


这篇关于Response.Write和Response.Redirect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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