Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to redirect a page in new window but not able to do this
explanation-i have gridview in which i have taken button field,on click of this button the downloading of the specified row will starts and after that i code responce.redirect this document but i want in new tab or window so plz tell me how it is posible

ASP
<asp:GridView ID="GridView1" runat="server"
              AutoGenerateColumns="False"
              DataSourceID="SqlDataSource3"
              onrowcommand="GridView1_RowCommand"
              DataKeyNames="DocID"
                            Height="50px" Width="50px" AllowSorting="True">
<Columns>
<asp:BoundField DataField="DocID" HeaderText="DocID"
                InsertVisible="False"
                ReadOnly="True"
                SortExpression="DocID" Visible="False" /><asp:ButtonField ButtonType="Image"
               ImageUrl="~/download-button.jpg"
               CommandName="Download"
               HeaderText="Download" ControlStyle-Height="20px"
       ControlStyle-Width="20px" >
                               <ControlStyle Height="20px" Width="20px"></ControlStyle>
                               </asp:ButtonField>
                           </Columns>
                       </asp:GridView>

and on cs page


C#
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "Download")
       {
           string fileName = string.Empty;
           int index = Convert.ToInt32(e.CommandArgument);
           GridViewRow row = GridView2.Rows[index];
           int documentID = Convert.ToInt32(GridView2.DataKeys[index].Value);
           SqlConnection con = new SqlConnection("Server=.;Database=E_Notes;integrated Security=true");
           //SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
           SqlCommand cmd = new SqlCommand("SELECT DocName FROM SaveDoc WHERE DocID = " + documentID, con);
           con.Open();
           SqlDataReader dReader = cmd.ExecuteReader();
           while (dReader.Read())
           {
               fileName = dReader["DocName"].ToString();
               byte[] documentBinary = (byte[])dReader["DocData"];
               FileStream fStream = new FileStream(Server.MapPath("../Docs/") + @"\" + fileName, FileMode.Create);
               fStream.Write(documentBinary, 0, documentBinary.Length);
               fStream.Close();
               fStream.Dispose();
           }
           con.Close();
           Response.Redirect(@"..\Docs\" + fileName);
       }
   }
[Edit]Code block added[/Edit]
Posted
Updated 12-May-13 2:56am
v3

1 solution

Hi,

Have a look here:
http://stackoverflow.com/a/8994342[^]
You can't is the short answer. The browser is the only thing that can open up a new window.

What you can do is send a chunk of html down the response that has a link with your url as an href, target="_blank" and a chunk of javascript onload of the form that fakes a click. If this doesn't work then use a window.open(url);
C#
response.write("<script>");
response.write("window.open('page.html','_blank')");
response.write("</script>"); 

 
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