HtmlTextWriter, Excel, New Window

  • Thread starter Thread starter Steve Schroeder
  • Start date Start date
S

Steve Schroeder

Using this code, how might I render the results to a new browser window and
leave the original as it? Thanks...

Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
dgInvoice.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

FYI...not my code, source is:
http://support.microsoft.com/default.aspx?scid=kb;en-us;317719

Thanks
 
There is a good Microsoft example (not the one you're quoting) showing this,
but the typical approach is:

<input type="button"
onclick='Window.Open("http://example.com/MyAspPage.aspx?bExcel=true")'>Click
here for Excel</input>

Then you use the QueryString server side to determine if it is a request for
Excel. There are numerous variations on this. What you don't want to do is
use the MIME type in the URL, because then someone can specify any random
MIME type and could use it as an attack mechanism (if unvalidated).
 
Yeah I've decided on automation, that's cool.

Running into the problem now of making a proper DHTML reference to the
datagrid. Not too familar with DHTML...

window.document.forms("MGInvoice").children("dgInvoice").outerhtml

Doesn't work, unfortunately...ideas?

Thanks
 
Back
Top