asp.net Response.Redirect跳出框架与打开窗口方法

asp教程.net Response.Redirect跳出框架与打开窗口方法

跳出框架大概会用到js top.location来实现。

Response.Write('<script>top.location='http://www.111cn.net';</script>');

Response.Redirect 方法是在服务器端进行转向,因此,除非使用 Response.Write("<script>window.location='url';</script>") 方法外,是不能在新窗口打开所指定的  URL 地址的。但是,如果仔细分析一下,如果设置 form 元素的 target 属性,还是有办法打开新窗口的

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Attributes.Add("onclick", "this.form.target='_newName'");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("http://dotnet.aspx.cc");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body id="b" runat="server">
<form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="打开新窗口或者新 Tab " />
</form>
</body>
</html>

如果需要设置弹出窗口的宽度和高度,可以修改为下面的方法:

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
      string WindowName = "win" + System.DateTime.Now.Ticks.ToString();
      Page.RegisterOnSubmitStatement("js", "window.open('','" + WindowName + "','width=600,height=200')");
        form1.Target = WindowName;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("http://www.111cn.net");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body id="b" runat="server">
<form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="打开新窗口或者新 Tab " />
</form>
</body>
</html>

时间: 2024-08-30 18:27:07

asp.net Response.Redirect跳出框架与打开窗口方法的相关文章

ASP.NET Response.Redirect的原理及实现

之前一直以为Response.Redirect ("default1.aspx")的运行原理是这样的

ASP中Response对象的集合、属性和方法介绍

 Response对象与一个HTTP响应相响应,通过该对象的属性和方法可以控制如何将服务器的数据发送到客户端浏览器. 在ASP脚本中使用Response对象时,遵循以下语法格式: Response.集合名 Response.属性名 Response.方法名 Response对象只有一个Cookies集合,该集合的各个属性如下表:   =================示例=========================== < %@ language="vbscript" co

如何用Response.Redirect方法传递汉字_自学过程

 使用Response.Redirect方法传递汉字,有时会发现所传递的值和接收到的内容不符,接受的值丢失了几个字或者变成了一堆乱码.那么如何才能保证所传递的汉字被正确接收呢?     页面A传递值的代码如下: string Message=Server.UrlEncode("欢迎学习ASP.NET!"); Response.Redirect("WebForm2.asp?Msg="+Message);    页面B接受值的代码如下: string Message=S

三种方法让Response.Redirect在新窗口打开_实用技巧

Response.Rederect在默认情况下是在本页跳转,所以除了在js中用window.open或是给A标签添加target属性之外,在后台似乎不能来打开新的页面,其实不然,通过设置form的target属性同样可以让Response.Rederect所指向的url在新的窗口打开.下面用三种方法来实现. 1 .给form指定target属性,那么本页面中所有的Response.Rederect都将在新的窗口中打开.代码如下: 复制代码 代码如下: protected void Page_Lo

如何Response.Redirect新的页面到指定的框架中(转)

如何Response.Redirect新的页面到指定的框架中 2000年10月31日 In the file that you wish to show up in the frame, add this line after the <BODY> tag:<BASE TARGET="framename">Then when you Response.Redirect to this ASP file, its contents will appear in t

JS实例:登陆失败后跳出框架打开

今天遇到个问题,后面在框架中,当判断登录失效后要返回登录页面,但登录页面却在框架内打开,我想让它直接跳出框架打开(这里不是打开新窗口),终于在网上找到了办法,分享给大家: echo "<script language=\"javascript\">alert('登录已失效或没有登录,请登录!');location.href='login.php';</script>"; 原内容是上边这样的,要想让它跳出框架打开登录页,需要使用下面的方法: e

如何Response.Redirect新的页面到指定的框架中

redirect|response|页面 In the file that you wish to show up in the frame, add this line after the <BODY> tag: <BASE TARGET="framename"> Then when you Response.Redirect to this ASP file, its contents will appear in the frame named "

Response.Redirect在新窗口打开的另一种方法

这里介绍Ihttpmodule处理请求管道的方法.Response.Redirect的原理是服务器设置返回http状态码为302,然后客户端执行跳转,用reflector可以看到.net的代码段. 以下是HttpResponse类的Redirect方法中的跳转代码 this.StatusCode = 0x12e; this.RedirectLocation = url; 所以,我们可以扩展Ihttpmodule来拦截http状态码,强制设为200,同时插入js代码段来实现新窗口打开.以下是Iht

ASP.NET中Response.Redirect()方法深度剖析

首先在Visual Studio中新建一个网站,在Default页面的Page_Load事件中写下 Response.Redirect("http://www.baidu.com"); 然后添加一个 Page_LoadComplete事件处理方法. 最终效果如下: 在12和17行设置了断点,方便对整个过程进行观察. 打开Fiddler,用以观察整个过程中的HTTP数据. 点击"调试"按钮 程序开始执行. 这时Fiddler中出现了一条数据: