开发者

Panel not displaying while dowloading file

I wrote download excel file in my code. If I click download button I need show ajax-load image (pnlPopup panel). But it is not displaying. I think because of Some "Response" statements (see below code). Download working fine, but simultaniously I want show loader panel too.

 <asp:Panel ID="pnlPopup" runat="server" visible="false">
    <div align="center" style="margin-top: 13px;">
       <asp:Image runat ="server" ID="imgDownload" src="Images/ajax-loader.gif" alt="" /> <br />
         <span class="updateProgressMessage">downloading ...</span>
    </div>

Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As EventArgs) 'Handles btnDownload.Click'
     Try

        pnlPopup.Visible = True
        Dim mSurvey As New Survey
        Dim mUser As New User
        Dim dtExcel As DataTable
        mUser = CType(Session("user"), User)
        dtExcel = mSurvey.CreateExcelWorkbook(mUser.UserID, mUser.Client.ID)
        Dim filename As String = "Download.xls"

        InitializeWorkbook()
        GenerateData(dtExcel)
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", filena开发者_如何学Pythonme))
        Response.Clear()
        Response.BinaryWrite(WriteToStream.GetBuffer)
        Response.End()

    Catch ex As Exception

    Finally
    End Try


End Sub


Your approach of showing the element via server side code is not going to work. When your button is clicked, your page will post back and the Excel file will be written to the response stream, and the page the user is viewing will not change, because you are not sending HTML back to the browser.

Instead, you can easily implement this by showing the image and text using Javascript. Simply have a div tag that is hidden (display: none; with CSS), and using the OnClientClick property of your button, write some Javascript to show the div tag.

As an alternate to writing the Javascript yourself, you could also look into the ASP.NET Ajax controls for help implementing this.


That way of doing it is just not going to work. You can't return both a downloadable file and an HTML file in the same response. It's probably best if you use JS to show that panel when the link is clicked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜