views:

27

answers:

1

I'm using Response.Write, Response.End to export to Excel/Word/csv. Is there a way to do this and also be able to change text on the page at the same time? For example, I have a controls within an UpdatePanel which I want to make visible/invisible.

+2  A: 

Update your page via the AJAX action and, in the process, write out some javascript that calls a separate page/handler that does the actual export.

 if (exporting)
 {
     string cacheID = Guid.NewGuid().ToString();
     Session[cacheID] = ...data or query to export...
     ScriptManager.RegisterStartupScript(Page,
             Page.GetType(),
             cacheid,
             "window.location = '/download.ashx?cacheid=" + cacheID + "';",
             True);
 }
tvanfosson
This will not work in a server farm.
SLaks
@SLaks - depends on where your sessions are stored. I'd assume in a clustered or load-balanced environment you'd be storing the sessions in the database. In that case, though, I'd probably store the means to generate the query rather than the results of the query.
tvanfosson