Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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: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
 

 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 12-May-13 3:45am
Edited 12-May-13 3:56am
ProgramFOX131.6K
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
response.write("<script>");
response.write("window.open('page.html','_blank')");
response.write("</script>"); 
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 12 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100