Response.Write("<script language='javascript'>alert('ok!');</script>");
            Response.Redirect(“other.aspx”);            return;
 这样写过之后,那个Response.Write()的提示信息不提示了,怎样解决?急盼!

解决方案 »

  1.   


    Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");
      

  2.   

      Response.Write("<script language='javascript'>alert('ok!');window.location.href='other.aspx'</script>");
      

  3.   

    楼主那样写,下面的代码就不执行了!  楼主可以Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");
    点击确定直接跳转!方便还简单!
      

  4.   

    使用
     Page.ClientScript.RegisterStartupScript(GetType(), "Err", "<script>alert('ok!');window.location.href='other.aspx';</script>", true); 
      

  5.   


    楼主,让我来为你一句一句解释一下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去执行了,还是同样向页面输出脚本,所以说,有先后顺序,先弹,后转。施主请给分
      

  6.   


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

  7.   

    调用     MessageBox mes = new MessageBox(HttpContext.Current);
      

  8.   

    将js脚本输出到页面上了,页面还没显示就跳转到其他页面
    ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" +msg + "');window.location.href='';</script>");
      

  9.   

    把跳转的js代码写在alert同个js段里面就可以啦
      

  10.   

    因为你重定向了 所以不提示了
      Response.Write("<script>  alert('ok!');window.location.href='other.aspx'; </script>");
      

  11.   


    如果按照这样的解释
    那么:            Response.Redirect(“other.aspx”);
                Response.Write("<script language='javascript'>alert('ok!');</script>");
              return;
    这样写会怎样,能弹出吗?
      

  12.   

        Response.Redirect(“other.aspx”);
        Response.Write("<script language='javascript'>alert('ok!');</script>");
        return;先转向,后写提示脚本,能弹出吗?
      

  13.   

    Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");只有这一种方法吗?难道就没有能够顺执行的方法?
      

  14.   

    Response.Write("<script> alert('ok!');window.location.href='other.aspx'; </script>");好多回答都是正确的啊!
      

  15.   

    不能啊。。
    Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");
    这样不就能解决你的问题么?
      

  16.   

    Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");我试了,这样能解决问题但是如果,有复杂情况要处理
    需要顺序处理几个环节,可能就不行了
    谁还有别的方法吗?谢谢了啊
      

  17.   

    ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' defer>alert('" +msg + "');window.location.href='';</script>");
      

  18.   

    Response.Write("<script language='javascript'>alert('ok!');window.location.href='other.aspx'</script>");
      

  19.   

    Response.Write("<script language='javascript'>alert('ok!');window.location.href='other.aspx'</script>");
      

  20.   

    可能我没说明白Response.Write("<script language='javascript'>alert('ok!');window.location.href='other.aspx'</script>");
    这样是能解决现在的问题假如,提示后,还要执行其他cs代码,执行完,再决定是不是window.location.href
    可能这样写就不行了这样的话,改怎样解决呢?
      

  21.   

    Response.Write("<script>alert('ok!');window.location.href='other.aspx';</script>");
      

  22.   

    提示后,还要执行其他cs代码,执行完,再决定是不是window.location.href有方法吗?怎样实现啊?
      

  23.   

     Page.ClientScript.RegisterStartupScript(GetType(), "Err", "<script>alert('ok!');window.location.href='other.aspx';</script>", true); 
    建议使用这个,
    这个比较好。
      

  24.   

     来晚了。。lz的错误是我在学习的时候最爱出的。。Response.Write("<script language='javascript'>alert('ok!');location.href='other.aspx'</script>");这样就没有问题。。
      

  25.   

    try:ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('ok!');window.location.href='other.aspx';</script>", false);
    //do your other work...
    ClientScript.RegisterStartupScript(this.GetType(), "nav", "<script>window.location.href='other.aspx';</script>", false);
      

  26.   

    上面写错了。。
    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);
      

  27.   

    Response.Write("<script>alert('ok!');location.href='other.aspx';</script>");
      

  28.   

    language='javascript' 改成 type='javascript' 试试
      

  29.   

     Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('ok!');window.location.href='other.aspx';</script>"); 
      

  30.   

    引用楼主 kkkmst 的回复:
    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视为过时,因为它需要把脚本 注册到页面的后面
      

  31.   

    谢谢大家的好心帮忙
    也许我还没说明白
    我要的效果是: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代码执行完了,再跳转页面我看了大家的好心解答,我一一都试了,虽然都还没实现到希望的功能,但还是谢谢了
    现在还想报着希望再等待一下,看有没有答案