当前位置:编程学习 > C#/ASP.NET >>

求Response.Redirect打开一个新窗口

求Response.Redirect打开一个新窗口
不需要另的方法,要能用我早用了 --------------------编程问答-------------------- 何必在一颗树上吊死 --------------------编程问答-------------------- 直接向比尔盖次提问 --------------------编程问答-------------------- 不知道楼主看过此文没有
http://www.cnblogs.com/goody9807/archive/2007/09/29/909758.html --------------------编程问答-------------------- http://blog.csdn.net/net_lover/archive/2007/09/24/1799094.aspx
http://weblogs.asp.net/infinitiesloop/archive/2007/09/25/response-redirect-into-a-new-window-with-extension-methods.aspx --------------------编程问答-------------------- 转
-----------------------------------------------
Response.Redirect 打开新窗口的两种方法
一般情况下,Response.Redirect 方法是在服务器端进行转向,因此,除非使用 Response.Write("<script>window.location='http://dotnet.aspx.cc';</script>") 方法外,是不能在新窗口打开所指定的  URL 地址的。但是,如果仔细分析一下,如果设置 form 元素的 target 属性,还是有办法打开新窗口的。下面就是可以采用的两种方法。 

方法一:在服务器端设置 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)
    {
        form1.Target = "_blank";
    }

    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>

办法二:采用客户端脚本的方法设置 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>

上面两种方法中的 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)
    {
      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://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>
--------------------编程问答-------------------- 孟子e章的方法 --------------------编程问答-------------------- 求Response.Redirect打开一个新窗口 
--------------------------
知道Redirect是什么意思,就應該知道不可能的,轉向而已.
另外,樓上"Response.Redirect打开新窗口的两种方法 "均是牽強附會,根本就沒有使用到Redirect --------------------编程问答-------------------- 錯了,樓上的樓上 --------------------编程问答-------------------- what mean?
打开一个新窗口啊,jsp
window.open() --------------------编程问答-------------------- 可楼主要redirect --------------------编程问答-------------------- 对于reasponse.redirect()也许大家都知道它的服务器端进行转向。因此,除非使用 Response.Write("<script>window.location='http://hi.baidu,com/19xier;</script>") 方法外,是不能在新窗口打开所指定的 URL 地址的。但是,如果仔细分析一下,如果设置 form 元素的 target 属性,还是有办法打开新窗口的。下面就是.

在page_load中

this.btngoto.Attributes.Add("onclick","this.form.target='_newName';"); //_newName 可以换成target的所有属性值。

btngoto_click(....)

{ response.redirect(http://hi.baidu.com/19xier);}

这样,就可以实现类似与response.write()的效果了。
这是我以前参考网上的资源整理的,通过测试的。 --------------------编程问答-------------------- lz真搞笑 --------------------编程问答-------------------- 为什么要那样呢 --------------------编程问答-------------------- 用Reflector看了一下框架,发现了一个更加简便的方法,不用修改任何已发布的程序

还是用ihttpmodule来处理请求链

编译一个ClassLibrary2.dll的类库,只包含如下一个类
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace ClassLibrary2
{
    public class Class1:System.Web.IHttpModule
    {
        public void Init(HttpApplication application)
        {

            application.PreSendRequestHeaders += new EventHandler(application_PreSendRequestHeaders);
        }

        void application_PreSendRequestHeaders(object sender, EventArgs e)
        {
            HttpApplication Application = (HttpApplication)sender;

            HttpContext context = Application.Context;

            if (context.Response.StatusCode == 302)
            {
                context.Response.Write("<script>window.open('"+context.Response.RedirectLocation+"')</script>");
                context.Response.StatusCode = 200;
            }

        }
 
        public  void Dispose()
        {
        }

        
    }
}


把ClassLibrary2.dll添加到web的bin目录并修改web.config文件,添加httpModules节点
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<authentication mode="Windows"/>
    <httpModules>
      <add name="MyModule" type="ClassLibrary2.Class1,ClassLibrary2"></add>
    </httpModules>
</system.web>
</configuration>
--------------------编程问答-------------------- 学习,怎么没解决方法 --------------------编程问答--------------------
挖坟.. --------------------编程问答-------------------- gv_btnRateDetail.Attributes.Add("OnClick", "javascript:ViewWeightBreakWithAllIn_" + this.SubheaderId + "_" + this.SegmentId + "('" + RowView.EstimatedCostChargeId + "');");

这样传参不更好。? --------------------编程问答-------------------- 感觉5#的好用 --------------------编程问答-------------------- 页面的 from 里,设置 target 属性 target=_blank --------------------编程问答-------------------- 写错了,是FORM里 --------------------编程问答--------------------  window.open('a.html', '_top') --------------------编程问答-------------------- Response.Redirect 打开新窗口的两种方法 

http://dotnet.aspx.cc/article/20bf99e7-2ef4-428c-9f60-5517d8bd58e5/read.aspx --------------------编程问答-------------------- 各位哥些,这是07年的帖子了,居然2011年还有人挖坟。。。。

我是在搜Response.Redirect的安全性搜到的。。。似乎在登录的时候没处理好可以获取到部分登录后的页面源代码。。。 --------------------编程问答-------------------- 好牛的历史帖子啊。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,