1

I have 2 button control. One is for download excel and another one is for a linkbutton that open new tab to another page. When I first click the download button is working fine. It able to download the excel file. But after I click the linkbutton that redirect to another page. I click the the download button again and it is not working and no excel file is download.

VB Net Code:

Protected Sub btnExcel_AllService_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
                CType(sender, Control).Parent.Visible = False
                Response.Clear()
                Response.Buffer = True
                Response.ContentType = "application/vnd.ms-excel"
                Response.AddHeader("content-disposition", "attachment;filename=AllServiceEndOfDay.xls")
                Response.Charset = ""
                EnableViewState = False
                Dim stringWriter As New System.IO.StringWriter()
                Dim htmlWriter As New HtmlTextWriter(stringWriter)
                isCustomRendering = True
                divExport.RenderControl(htmlWriter)
                Dim style = "<style> td { mso-number-format:\@; } </style> "
                Response.Write(style)
                Response.Write(stringWriter)
                Response.End()

                isCustomRendering = False
                EnableViewState = True
            End Sub


     Protected Sub LinkButton_Telco(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonTelco.Click
                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "key", "window.open('index.aspx');", True)
            End Sub
DroneLord
  • 11
  • 1
  • Start using a specialized library for creating Excel files, like [EPPlus](https://github.com/JanKallman/EPPlus). [Example here](https://stackoverflow.com/a/47293207/5836671) and [here](https://stackoverflow.com/a/39513057/5836671). All you are doing now is creating a HTML page with an .xls extension. – VDWWD Mar 06 '19 at 07:31
  • But my goal is to download all the formview within the div container. – DroneLord Mar 06 '19 at 07:49

0 Answers0