Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

XML
<%@ 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>


form2:

XML
<%@ 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......
Posted
Updated 5-Oct-12 0:42am
v8
Comments
vyas_pratik20 5-Oct-12 4:40am    
which version of IE
CH Guravaiah 5-Oct-12 4:46am    
IE 8 AND ALSO OPEN ANY VERSION. PLEASE GIVE ME REPLY.
Member 4135621 23-Feb-13 2:23am    
czsdsd

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>


Add this in the Page_Load function of your C#:
C#
protected void Page_Load(object sender, EventArgs e)
      {
          try
          {
              if (Request.QueryString["newtab"].ToLower() == "true")
              {
                  Response.Redirect("NewPage.aspx");
              }
          }
          catch { }
          form1.Target = "_blank";
      }


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.
 
Share this answer
 
v3
Comments
fjdiewornncalwe 5-Oct-12 10:27am    
Will this work. Yes. But I have a problem with generating useless extra postbacks to the server. The philosophy should always be to push as much work to the client machine as possible. Always build as though you'll have millions of users.
Member 4135621 23-Feb-13 4:31am    
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Request.QueryString["newtab"].ToLower() == "true")
{
Response.Redirect("NewPage.aspx");
}
}
catch { }
form1.Target = "_blank";
}
Use window.location keyword if window.open with target = "_new" was not working..

Thanks,
Ambesha
 
Share this answer
 
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.
 
Share this answer
 
Window.open("url") is enough without specifying any height and width etc...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900