如何使用asp.net将文件打开到浏览器的新选项卡中

问题描述:

大家好,我试图将文件打开到新标签页.这里的问题是,当单击按钮时,它将在Chrome浏览器中打开文件.但是在Internet Explorer中,将文件打开到新窗口中.我想在所有浏览器的新标签页中打开文件.

形式1:

Hi Guys , I tried to open file into new tab. here problem is when click on the button it will open the file in Chrome browser. But in internet explorer,open file into the new window. I want to open the file into new tab of all browsers.

form1:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Submit"

            OnClientClick="form1.target='_blank';" Height="32px"

            onclick="Button1_Click" Width="75px" />
    </div>
    </form>
</body>
</html>



形式2:



form2:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>welcome to new Tab </h1>
    </div>
    </form>
</body>
</html>





请任何人给我答复...





please any give me reply......

将您第一页的表单更改为:

Change the form in your first page into this:

<form id="form1" runat="server" method="get">
   <asp:HiddenField runat="server" value="true" id="newtab" />
    <asp:Button id="Button1" runat="server" height="32px"
            Width="75px" Text="Submit"  />
</form>



将其添加到C#的Page_Load函数中:



Add this in the Page_Load function of your C#:

protected void Page_Load(object sender, EventArgs e)
      {
          try
          {
              if (Request.QueryString["newtab"].ToLower() == "true")
              {
                  Response.Redirect("NewPage.aspx");
              }
          }
          catch { }
          form1.Target = "_blank";
      }



代码的作用:

当您按下提交"按钮时,
您将被重定向到同一页面,但值"newtab"
Request.QueryString中的设置为"true".

Response.Redirect将您重定向到新页面,
然后form1.Target = ''_blank''打开新的pab页面.

希望这对您有帮助.



What the code does:

When you press the Submit button,
you''ll be redirected to the same page, but the value "newtab"
in Request.QueryString is set to "true".

Response.Redirect redirects you to a new page,
and form1.Target = ''_blank'' opens the new pab page.

Hope this helps.


如果目标为"_new"的window.open无法正常工作,请使用window.location关键字..

谢谢,
Ambesha
Use window.location keyword if window.open with target = "_new" was not working..

Thanks,
Ambesha


您实际上并没有控制权.如果用户已将其浏览器配置为打开新窗口,则新文档将在新窗口中打开.如果他们已经配置为打开新的选项卡,那么您将得到.您实际上并没有从应用程序端对此进行控制.
You don''t really have control of that. If the user has configured their browser to open new windows, your new documents will open in a new window. If they have configured to open new tabs, then that is what you will get. You don''t really have control of this from the application side.