0

I have an aspx (say 1.aspx) page from where first I am downloading a pdf file and then I want to redirect to some 2.aspx page. The code is this:

protected void buttSubmit_Click(object sender, EventArgs e)//Submit button to generate PDF
    {            
            if (intInvoID > 0)
            {
               UpdateInvoice();          
            }
            else
            {
                SaveInvoice();      
            }

            GenearatePDf(strheader, htrFooter, strContact, strExihibition, strPaymentDetails, strNotes);
            Response.AddHeader("Refresh", "12;URL=~/expo_crm/invoice/View_Invoices.aspx");

        }
    }

Here,I am not able to redirect to View_Invoices.aspx. I tried using Response.header.But its not working.

private void GenearatePDf(string strheader, string strFooter, string strContact, string strExihibition, string strPaymentDetails, string strNotes)
    {
             Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Invoice_" + txtCompanyName.Text.Trim() + ".pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();

            StringReader srHtmlText = new StringReader(sbHtmlText.ToString());
            Document pdfDocument = new Document(PageSize.A4, 40f, 40f, 15f, 2f);

            iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDocument);

            PdfWriter pdfDoc1 = PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
            var page = new ITextEvents();
            page.email = txtExpogrEmail.Text.Trim();
            pdfDoc1.PageEvent = page;



            pdfDocument.Open();
            pdfDocument.Add(ph1);
            pdfDocument.Add(tblBlank);
            pdfDocument.Add(tblAddInfo);

            pdfDocument.Add(tblCon);
            pdfDocument.Add(tblExhibition);
            pdfDocument.Add(tblNotes);
            pdfDocument.Add(iHeader);

            pdfDocument.Add(jpg);
            pdfDocument.Add(jpg1);

            htmlparser.Parse(srHtmlText);
            pdfDocument.Close();
            Response.Write(pdfDocument);
            //Response.End();}
  • Have you tried Response.Redirect ? – Anthony McGrath Jan 06 '18 at 06:31
  • yes...its not working –  Jan 06 '18 at 06:32
  • Why don't you show us what you tried? –  Jan 06 '18 at 06:34
  • 1
    I would suggest redirecting to page 2 first, passing a parameter to signify the PDF download, then download the pdf file once on page 2. – Anthony McGrath Jan 06 '18 at 06:34
  • my page 2 is about viewing the invoice.My pdf is gettting generated but after generating pdf it should go to viewinvoice.aspx page.So i have added Response.header(--).But its not working.i tried using breakpoint.it goes to till generatePdf mtd and henerating pdf and does not go to Response.header –  Jan 06 '18 at 06:41
  • https://stackoverflow.com/questions/2288941/redirecting-a-page-after-a-pdf-download – Aria Jan 06 '18 at 06:51
  • yes aria..i tried using reponse.addheader but it dint worked. –  Jan 06 '18 at 06:57
  • Let us see `GenearatePDf` code. – Aria Jan 06 '18 at 07:20
  • GenearatePDf(strheader, htrFooter, strContact, strExihibition, strPaymentDetails, strNotes); ----------------------------------------------------------------------------- Response.Redirect("~/expo_crm/invoice/View_Invoices.aspx"); Response.End();--------------i slightly modify the code...here it is redirecting to a page2.aspx but not generating the pdf. –  Jan 06 '18 at 07:30
  • @Aria....I have just added the code that generates pdf –  Jan 06 '18 at 07:34

1 Answers1

0

It might be the case that the Refresh header only works when you're serving a HTML document. Per this question, it is equivalent to the <meta http-equiv="refresh" url="..." /> head tag. Which can only appear in an html document.

Horia Coman
  • 8,681
  • 2
  • 23
  • 25