欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP.NET打开新页面而不关闭原来的页面 实例代码

程序员文章站 2024-02-28 22:53:58
复制代码 代码如下:respose.write("w...
复制代码 代码如下:

respose.write("<script     language='javascript'>window.open('"+     url     +"');</script>"); (打开简洁窗口):
respose.write("<script     language='javascript'>window.open('"     +     url     +     "','','resizable=1,scrollbars=0,status=1,menubar=no,toolbar=no,location=no,     menu=no');</script>");

1. response.redirect("xxx.aspx",true)——直接转向新的页面,原窗口被代替;
2. response.write("<script>window.open('xxx.aspx','_blank')</script>")——原窗口保留,另外新增一个新页面;
3. response.write("<script>window.location='xxx.aspx'</script>")——打开新的页面,原窗口被代替;
4. server.transfer("xxx.aspx")——打开新的页面;
5. response.write("<script>window.showmodelessdialog('xxx.aspx')</script>")——原窗口保留,以对话框形式打开新窗口;
6. response.write("<script>window.showmodeldialog('xxx.aspx')</script>")——对话框形式打开新窗口,原窗口被代替;
也可以自己写方法:
复制代码 代码如下:

public static void showmessage(system.web.ui.page page, string msg)
{
    page.clientscript.registerclientscriptblock(page.gettype(), "a", "alert('" + msg.tostring() + "');", true);
}

调用的时候:
showmessage(this,"要显示的消息");
下面是整个类的代码你可以挑着用
复制代码 代码如下:

using system;
using system.collections.generic;
using system.text;
namespace worklogic
{
    /// <summary>
    /// 显示消息提示对话框。
    /// </summary>
    public class messagebox
    {
        private messagebox()
        {
        }
        /// <summary>
        /// 显示消息提示对话框
        /// </summary>
        /// <param name="page">当前页面指针,一般为this</param>
        /// <param name="msg">提示信息</param>
        public static void showmessage(system.web.ui.page page, string msg)
        {
            //page.registerstartupscript("message", "alert('" + msg.tostring() + "');");
            page.clientscript.registerclientscriptblock(page.gettype(), "a", "alert('" + msg.tostring() + "');", true);
        }
        public static void showmessage(system.web.ui.usercontrol control, string msg)
        {
            control.page.clientscript.registerclientscriptblock(control.page.gettype(), "b", "alert('" + msg.tostring() + "');", true);
        }
        /// <summary>
        /// 控件点击 消息确认提示框
        /// </summary>
        /// <param name="page">当前页面指针,一般为this</param>
        /// <param name="msg">提示信息</param>
        public static void showconfirm(system.web.ui.webcontrols.webcontrol control, string msg)
        {
            //control.attributes.add("onclick","if (!window.confirm('"+msg+"')){return false;}");
            control.attributes.add("onclick", "return confirm('" + msg + "');");
        }
        /// <summary>
        /// 显示消息提示对话框,并进行页面跳转
        /// </summary>
        /// <param name="page">当前页面指针,一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标url</param>
        public static void showandredirect(system.web.ui.page page, string msg, string url, string frame)
        {
            stringbuilder builder = new stringbuilder();
            builder.append("<script language='javascript' defer>");
            builder.appendformat("alert('{0}');", msg);
            builder.appendformat("top." + frame + ".location.href='{0}'", url);
            builder.append("</script>");
            page.clientscript.registerstartupscript(page.gettype(), "message", builder.tostring());
        }
        /// <summary>
        /// 输出自定义脚本信息
        /// </summary>
        /// <param name="page">当前页面指针,一般为this</param>
        /// <param name="script">输出脚本</param>
        public static void responsescript(system.web.ui.page page, string script)
        {
            page.clientscript.registerstartupscript(page.gettype(), "message", "<script language='javascript' defer>" + script + "</script>");
        }
        /// <summary>
        /// 显示消息提示对话框,并进行页面跳转
        /// <param name="page">当前页面指针,一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标url</param>
        public static void showandredirect(system.web.ui.page page, string msg, string url)
        {
            stringbuilder builder = new stringbuilder();
            builder.append("<script language='javascript' defer>");
            builder.appendformat("alert('{0}');", msg);
            builder.appendformat("top.location.href='{0}'", url);
            builder.append("</script>");
            page.clientscript.registerstartupscript(page.gettype(), "message", builder.tostring());
       }
}
}