locked
how to open a new window/tab in asp:Button RRS feed

  • Question

  • User1046245955 posted

    how to open a new window/tab using c# .net

    here's my code:

    .aspx

    <asp:Button ID="bttnpdf" runat="server" Text="<%$ Resources:LocalizedResources, View %>" Width="120px" CssClass="btn yellow pull-left" OnClick="bttnpdf_Click" />

    code behind:

    protected void bttnpdf_Click(object sender, EventArgs e)
    {

    string mattach = Session["atta"].ToString();


    string FilePath = @"http://server/FileAttachment/" + mattach;

    WebClient User = new WebClient();
    Byte[] FileBuffer = User.DownloadData(FilePath);
    if (FileBuffer != null)
    {
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", FileBuffer.Length.ToString());
    Response.BinaryWrite(FileBuffer);
    }
    }

    Tuesday, April 30, 2019 6:30 AM

All replies

  • User283571144 posted

    Hi paminchever,

    how to open a new window/tab using c# .net

    According to your description and codes, I couldn't understand your requirement clearly.

    I found your codes is used to download the PDF file from another path.

    If you want to open the PDF file in the new windows, I suggest you could refer to below codes:

            protected void bttnpdf_Click(object sender, EventArgs e)
            {
                string FilePath = @"http://server/FileAttachment/" + "a";
    
                Response.Redirect(FilePath);
            }

    If I misunderstand your requirement, please feel free to let me know.

    Best Regards,

    Brando

    Wednesday, May 1, 2019 2:05 AM