Response.Write("<script language='javascript'>alert('ok!');</script>");
Response.Redirect(“other.aspx”); return;
这样写过之后,那个Response.Write()的提示信息不提示了,怎样解决?急盼!
Response.Redirect(“other.aspx”); return;
这样写过之后,那个Response.Write()的提示信息不提示了,怎样解决?急盼!
调试欢乐多
Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");
点击确定直接跳转!方便还简单!
Page.ClientScript.RegisterStartupScript(GetType(), "Err", "<script>alert('ok!');window.location.href='other.aspx';</script>", true);
楼主,让我来为你一句一句解释一下1. Response.Write("<script language='javascript'>alert('ok!');</script>");这行代码的主要目的就是向页面上输出一段Javascript脚本,这个脚本的主要目的就是弹出一个窗口OK
2.Response.Redirect(“other.aspx”);这一句是利用http头进行转向,也就是说,浏览器,接到这句话传递过去的http头,就会直接转向那么你的问题得到解决了,第一步的脚本,是要等页面呈现阶段才能得到执行的,而Response.Redirect是在浏览器接收到http头的时候就发挥作用了,所以很明显,你写了Response.Redirect以后,根本就等不到呈现,页面就转向了,所以OK弹不出来另外有施主这么写Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");这个就是将弹出窗口和转向都用javascript去执行了,还是同样向页面输出脚本,所以说,有先后顺序,先弹,后转。施主请给分
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;/// <summary>
/// MessageBox 的摘要说明
/// </summary>
public class MessageBox
{ private HttpContext myContext = null;
public MessageBox(HttpContext CurrentContext)
{
myContext = CurrentContext;
}
/// <summary>
/// 自定义弹出窗口内容
/// </summary>
/// <param name="msg"></param>
public void AlertMsg(string msg)
{
//myContext.Response.Write("<script>alert('" + msg + "');</script>");
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "<script>alert('" + msg + "');</script>", false);
}
/// <summary>
/// 自定义弹出窗口内容并转向一个新的页面
/// </summary>
/// <param name="msg">自定义消息</param>
/// <param name="Url">需要转到的新页面</param>
public void Show(string msg, string Url)
{
//myContext.Response.Write("<script>alert('" + msg + "');javascript:location='"+Url+"';</script>");
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "<script>alert('" + msg + "');javascript:location='" + Url + "';</script>", false); }
/// <summary>
/// 自定义弹出窗口内容,自定义是否关闭当前页面
/// </summary>
/// <param name="msg"></param>
/// <param name="close"></param>
public void Show(string msg, bool close)
{
if (close)
{
// myContext.Response.Write("<script>alert('" + msg + "');javascript:window.close();</script>");
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "<script>alert('" + msg + "');javascript:window.close();</script>", false);
}
else
{
//myContext.Response.Write("<script>alert('" + msg + "');</script>");
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "aaa", "<script>alert('" + msg + "');</script>", false);
}
}
/// <summary>
/// 自定义转向新页面
/// </summary>
/// <param name="Url">新页面地址</param>
public void Show(string Url)
{
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "", "javascript:location='" + Url + "';", true); }
/// <summary>
/// 自定义弹出模式窗体
/// </summary>
/// <param name="url">页面地址</param>
/// <param name="height">模式窗体的高</param>
/// <param name="width">模式窗体的宽</param>
public void ShowDialog(string url,int height,int width)
{
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "", "window.showModalDialog('"+url+"','window','status=no;dialogWidth="+width+"px;dialogHeight="+height+"px;menu=no;resizeable=yes;scroll=yes;location=no');window.location.reload();", true);
}
/// <summary>
/// 自定义输出语句,相当于Response.Write()
/// </summary>
/// <param name="js">javascript语句,前后不用加"<script>"</param>
public void WriteJs(string js)
{
ScriptManager.RegisterStartupScript((System.Web.UI.Page)myContext.CurrentHandler, typeof(System.Web.UI.Page), "",js, true);
}
}
ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" +msg + "');window.location.href='';</script>");
Response.Write("<script> alert('ok!');window.location.href='other.aspx'; </script>");
如果按照这样的解释
那么: Response.Redirect(“other.aspx”);
Response.Write("<script language='javascript'>alert('ok!');</script>");
return;
这样写会怎样,能弹出吗?
Response.Write("<script language='javascript'>alert('ok!');</script>");
return;先转向,后写提示脚本,能弹出吗?
Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");
这样不就能解决你的问题么?
需要顺序处理几个环节,可能就不行了
谁还有别的方法吗?谢谢了啊
这样是能解决现在的问题假如,提示后,还要执行其他cs代码,执行完,再决定是不是window.location.href
可能这样写就不行了这样的话,改怎样解决呢?
建议使用这个,
这个比较好。
//do your other work...
ClientScript.RegisterStartupScript(this.GetType(), "nav", "<script>window.location.href='other.aspx';</script>", false);
ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('ok!');</script>", false);
//do your other work...
ClientScript.RegisterStartupScript(this.GetType(), "nav", "<script>window.location.href='other.aspx';</script>", false);
C# code
Response.Write("<script language='javascript'>alert('ok!');</script>");
Response.Redirect(“other.aspx”);return;这样写过之后,那个Response.Write()的提示信息不提示了,怎样解……楼主,让我来为你一句一句解释一下1. Response.Write("<script language='javascript'>alert('ok!');</script>");这行代码的主要目的就是向页面上输出一段Javascript脚本,这个脚本的主要目的就是弹出一个窗口OK
2.Response.Redirect(“other.aspx”);这一句是利用http头进行转向,也就是说,浏览器,接到这句话传递过去的http头,就会直接转向那么你的问题得到解决了,第一步的脚本,是要等页面呈现阶段才能得到执行的,而Response.Redirect是在浏览器接收到http头的时候就发挥作用了,所以很明显,你写了Response.Redirect以后,根本就等不到呈现,页面就转向了,所以OK弹不出来另外有施主这么写Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");这个就是将弹出窗口和转向都用javascript去执行了,还是同样向页面输出脚本,所以说,有先后顺序,先弹,后转。施主请给分
---------------->正解,ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('ok!');</script>", false 这个2005以后的版本里面已经被ms视为过时,因为它需要把脚本 注册到页面的后面
也许我还没说明白
我要的效果是:Script(this.GetType(), "msg", "<script>alert('ok!');</script>", false);
//do other cs代码 work...
Script(this.GetType(), "nav", "<script>window.location.href='other.aspx';</script>", false);就是说一个脚本提示完了,执行其他的cs代码,cs代码执行完了,再跳转页面我看了大家的好心解答,我一一都试了,虽然都还没实现到希望的功能,但还是谢谢了
现在还想报着希望再等待一下,看有没有答案