Response.Redirect的新窗口 [英] Response.Redirect to new window

查看:178
本文介绍了Response.Redirect的新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个的Response.Redirect(MyPage.aspx)但它在一个新的浏览器窗口中打开。我不使用JavaScript脚本注册方法之前做到了这一点。我只是不记得如何?

I want to do a Response.Redirect("MyPage.aspx") but have it open in a new browser window. I've done this before without using the JavaScript register script method. I just can't remember how?

推荐答案

我只是找到了答案和它的作品:)

I just found the answer and it works :)

您需要将以下内容添加到您的服务器端的链接/按钮:

You need to add the following to your server side link/button:

OnClientClick="aspnetForm.target ='_blank';"

我的整个按钮code看起来是这样的:

My entire button code looks something like:

<asp:LinkButton ID="myButton" runat="server" Text="Click Me!" 
                OnClick="myButton_Click" 
                OnClientClick="aspnetForm.target ='_blank';"/>

在服务器端onclick我做了的Response.Redirect(MyPage.aspx); 和页面在新窗口中打开

In the server side OnClick I do a Response.Redirect("MyPage.aspx"); and the page is opened in a new window.

您需要添加另一部分是固定形式的目标,否则每一个环节将打开一个新窗口。要做到这一点补充在弹出窗口的标题下面。

The other part you need to add is to fix the form's target otherwise every link will open in a new window. To do so add the following in the header of your POPUP window.

<script type="text/javascript">
    function fixform() {
        if (opener.document.getElementById("aspnetForm").target != "_blank") return;
        opener.document.getElementById("aspnetForm").target = "";
        opener.document.getElementById("aspnetForm").action = opener.location.href;
    }
</script>

<body onload="fixform()">

这篇关于Response.Redirect的新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆