Calling Response to WriteFile and also update page problem

J

John

Hello,

I have a VB.net app the sends an Excel file to the browser and it also need
to hide some fields on the form at the same time. But the form is not hiding
the controlls. The "Open/Save/Cancel" diaolog opens on the browser but the
page stays the same, the controls are not hidden. Below is a sample of the
code I'm using to send the file to the browser and hide the controls. What
am I doing wrong?

Sub SendReport(ByRef SaveFile As String)

tblMessage.Visible = False

lblMessage.Text = ""

'Response.Flush()

'Response.Close()

'Response.ClearContent()

'Response.ClearHeaders()

Response.ContentType = "application/vnd.ms-excel"

Response.WriteFile(SaveFile)

Response.End()

'Response.Flush()

'Response.Close()

Kill(SaveFile)

End Sub



Thanks,

John Wilhelm

(e-mail address removed)
 
G

Guest

Hello,

I have a VB.net app the sends an Excel file to the browser and it also need
to hide some fields on the form at the same time. But the form is not hiding
the controlls. The "Open/Save/Cancel" diaolog opens on the browser but the
page stays the same, the controls are not hidden. Below is a sample of the
code I'm using to send the file to the browser and hide the controls. What
am I doing wrong?

Sub SendReport(ByRef SaveFile As String)

    tblMessage.Visible = False

    lblMessage.Text = ""

    'Response.Flush()

    'Response.Close()

    'Response.ClearContent()

    'Response.ClearHeaders()

    Response.ContentType = "application/vnd.ms-excel"

    Response.WriteFile(SaveFile)

    Response.End()

    'Response.Flush()

    'Response.Close()

    Kill(SaveFile)

End Sub

Thanks,

John Wilhelm

(e-mail address removed)

Hi John,

after you set ContentType = "application/vnd.ms-excel" and call
Response.End you will not be able to "refresh" the page. That's
because you cannot combine text/html and application/vnd.ms-excel in
the same response. You can try to fix it by doing a small trick with
meta tag

instead of

Response.ContentType = "application/vnd.ms-excel"
Response.WriteFile(SaveFile)
Response.End()
Kill(SaveFile)

do

Dim meta As HtmlMeta = New HtmlMeta()
meta.HttpEquiv = "Refresh"
meta.Name = "keywords"
meta.Content = "0;URL=" & SaveFile <-- e.g. mydoc.xls
Me.Header.Controls.Add(meta)

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top