2012年3月26日月曜日

Response.write in Update Panel

Is it possible to use a response.write in an update panel? I have a button converting a datagrid to excel using response.write. The button will work fine outside of the update panel but when I try it inside the update panel I am getting an error.

Try a response.clear

 Response.Clear() Response.AddHeader("content-disposition","attachment; filename=Survey_Results.xls") Response.Charset ="" Response.Cache.SetCacheability(HttpCacheability.NoCache)Dim stringWriterAs System.IO.StringWriter =New System.IO.StringWriter()Dim htmlWriteAs System.Web.UI.HtmlTextWriter =New HtmlTextWriter(stringWriter) stringWriter.Write("Question,Option,Option Type,Is Correct?,UserID" & vbCrLf)Dim colSurveyResultInfoAs List(Of SurveyResultInfo) = SurveyOptionController.GetSurveyResultData(ModuleId)Dim objSurveyResultInfoAs SurveyResultInfoFor Each objSurveyResultInfoIn colSurveyResultInfo stringWriter.Write(objSurveyResultInfo.Question &"," & objSurveyResultInfo.OptionName &"," & objSurveyResultInfo.OptionType &"," & objSurveyResultInfo.IsCorrect &"," & objSurveyResultInfo.UserId & vbCrLf)Next Response.Write(stringWriter.ToString()) Response.Flush() Response.Close()

After a little more research I found the answer.

<Triggers>
<asp:PostBackTrigger ControlID="btnExport" />
</Triggers>

http://ajax.asp.net/docs/mref/T_System_Web_UI_PostBackTrigger.aspx


You can't send a traditional octet stream file response in a partial postback because there isn't an HTTP response coming back to the browser. It's just a string returned to the XmlHTTPRequest.

However, you canuse an iframe to accomplish asynchronous file downloads.

0 件のコメント:

コメントを投稿