响应对象不返回Excel的数据流中的更新面板? [英] Response Object not returning Excel stream in update Panel?

查看:118
本文介绍了响应对象不返回Excel的数据流中的更新面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成后,一个按钮在更新面板中单击Excel文件。它抛出一个解析错误。请参见下面的code。

如果我把按钮更新面板它是工作的罚款之外。为什么不工作的更新面板?

  Response.ContentType =应用程序/ vnd.ms-EXCEL
Response.AddHeader(内容处置,
                    的String.Format(附件;文件名= {0},文件名))
Response.Clear()
Response.BinaryWrite(WriteToStream.GetBuffer)
HttpContext.Current.ApplicationInstance.CompleteRequest()

专用功能WriteToStream()作为MemoryStream的
    '编写簿的流数据到根目录
    昏暗的文件作为MemoryStream的=新的MemoryStream
    hssfworkbook.Write(文件)
    返回文件
端功能
 

解决方案

您不应该重写一个更新面板的响应。在ASP更新板工作,整个页面执行的方式,并更新面板内的部分从响应拉出并发送给客户端(作为响应XHRequest)。当你做了 Response.BinaryWrite ,你擦掉标准输出服务器正在期待能够解析通过新的标记就是了发送。

如果你想改变面板中的内容有按钮触发更新面板的唯一原因是。否则,只需确保按钮没有面板的触发。如果按钮必须留在面板上,将它添加到面板的触发部分为 PostBackTrigger (注意缺少异步上)。

例如:

 < ASP:UpdatePanel的ID =somePanel的UpdateMode =条件=服务器>
  < /的ContentTemplate>
    不断更新的内容?
    < ASP:按钮的ID =someButton文本=点击我!
                的OnClick =someButton_Click=服务器>
    其他的变化内容?
  < /的ContentTemplate>
  <触发器>
    < ASP:PostBackTrigger控件ID =someButton/>
  < /触发器>
< / ASP:UpdatePanel的>
 

I am generating an Excel file upon a click of a button in an update panel. It is throwing a parsing error. Please see below code.

If I keep the button outside the update panel it is working fine. Why isn't it working in the update Panel?

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", 
                    String.Format("attachment;filename={0}", filename))
Response.Clear()
Response.BinaryWrite(WriteToStream.GetBuffer)
HttpContext.Current.ApplicationInstance.CompleteRequest()

Private Function WriteToStream() As MemoryStream
    'Write the stream data of workbook to the root directory
    Dim file As MemoryStream = New MemoryStream
    hssfworkbook.Write(file)
    Return file
End Function

解决方案

You shouldn't be overwriting the response for an update panel. The way the ASP update panels work, the entire page executes, and the portion within the update panel is pulled from the response and sent to the client (as a response to an XHRequest). When you do a Response.BinaryWrite, you are obliterating the standard output that the server is expecting to be able to parse through for the new markup it wants to send.

The only reason to have the button trigger the update panel is if you want to change the content within that panel. Otherwise, simply make sure the button is not a trigger of the panel. If the button must stay in the panel, add it to the panel's trigger section as a PostBackTrigger (note the lack of Async on that).

E.g.:

<asp:UpdatePanel ID="somePanel" UpdateMode="Conditional" runat="server">
  </ContentTemplate>
    changing content?
    <asp:Button id="someButton" Text="click me!" 
                OnClick="someButton_Click" runat="server">
    other changing content?
  </ContentTemplate>
  <Triggers>
    <asp:PostBackTrigger ControlID="someButton" />
  </Triggers>
</asp:UpdatePanel>

这篇关于响应对象不返回Excel的数据流中的更新面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆