Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download window opening twice on Export event

Status
Not open for further replies.

ChasBoots

MIS
Jul 23, 2002
24
US
I've searched virtually every possible place I can to find an answer. I have come up empty. I am using the typical code to export a datagrid to Excel. However, when the "File Download" dialog re-appears if clicking the Open button. What am I missing? If I remove the Response.Addheader line, everything works as expected. I would prefer to either force a filename or leave it workbook unnamed with a status of unsaved. My code follows:

Code:
    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Dim s, f, g, h, w, o, pSql, pFarm, pAppName As String

        s = lbSql.Items.Item(0).Value
        f = lbSql.Items.Item(1).Value
        w = lbSql.Items.Item(2).Value
        g = lbSql.Items.Item(3).Value
        h = lbSql.Items.Item(4).Value
        o = lbSql.Items.Item(5).Value
        pSql = s & f & w & g & h & o
        pFarm = farmselect()
        pAppName = dd_AppName.SelectedItem.ToString
        ClearControls(dgResults)
        Response.Clear()
        Response.AppendHeader("content-disposition", "attachment;filename=" & pAppName.ToString & ".xls")
        Response.ContentType = "application/vnd.ms-excel"
        Response.Charset = ""
        EnableViewState = False

        Dim stringWrite As New System.IO.StringWriter()
        Dim htmlWrite As New HtmlTextWriter(stringWrite)
        dgResults.AllowCustomPaging = False
        dgResults.AllowPaging = False
        dgResults.AllowSorting = False
        exp_Status = False
        Bind_dgResults(pSql)
        dgResults.RenderControl(htmlWrite)
        Response.Write(stringWrite.ToString())
        Response.Flush()
        Response.End()

    End Sub

If anyone requires additional info, please let me know. Thanks for your help.
 
try changing Dim htmlWrite As New HtmlTextWriter(stringWrite)

to

Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)



 
Thanks for the suggestion but that did not resolve the problem....
 
Try to step through the code, you can easily spot the problem.

Sharing the best from my side...

--Prashant--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top