在浏览器保存对话框中显示 Response.Binarywrite 或打开新窗口并在保存后关闭
我的问题看起来像这样。 我有一个包含文档(Id)的网格。现在,当有人单击一行时,我希望允许他下载或显示该文档。但为了让它更简单,我们假设我会通过单击按钮来完成此操作。我尝试了两种方法,但对我来说都不起作用。
我尝试在按钮上单击response.binarywrite:
Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.ContentType = "应用程序/postscript mime"; Response.AddHeader("内容处置", "附件; filename=test.ps"); Response.AddHeader("内容长度", _excuteGetDocumentResult.Length.ToString()); Response.ContentEncoding = new System.Text.UTF8Encoding(); Response.BinaryWrite(_excuteGetDocumentResult);
但是没有任何反应,当我尝试修改此代码时,我通常会收到一些 javascript 错误,说明有关更改响应的内容...
第二种方法正在打开新窗口并在页面加载时添加上面的代码。
<asp:Button Text="ShowResult" OnClientClick="radopen('ShowResult.aspx','ShowDocumentDialog'); return false;"
runat="server" />
第二种方法有效,但在保存或取消资源管理器保存文件对话框窗口后,我打开的窗口仍然存在。我尝试添加一些 javascript 来关闭它,但它仅在加载页面上没有 response.binarywrite 的情况下有效...
有什么想法可以实现我想要的吗?
My problem looks like this.
I have a grid with documents (Id's). Now when somebody clicks at a row I would like to allow him to download or show that document. But to make it esier let's say that I would do this on a button click. I tried two approaches but none of them worked form me.
I tried to response.binarywrite on the button click:
Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.ContentType = "application/postscript mime"; Response.AddHeader("content-disposition", "attachment; filename=test.ps"); Response.AddHeader("content-length", _excuteGetDocumentResult.Length.ToString()); Response.ContentEncoding = new System.Text.UTF8Encoding(); Response.BinaryWrite(_excuteGetDocumentResult);
But nothing happens and when I try to modify this code I usually get some javascript errors saying sommething about changing the response...
The socond approach was opening new window and on page load adding the code above.
<asp:Button Text="ShowResult" OnClientClick="radopen('ShowResult.aspx','ShowDocumentDialog'); return false;"
runat="server" />
The socond approach works but my opened window still exists after saving or canceling the explorer saving file dialog window. I tried to add some javascript to close it but it only works where there is no response.binarywrite on the load page...
Any ideas how I can achive what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在方法 1 中,
在
Response.BinaryWrite(_excuteGetDocumentResult);
之后尝试Response.End();
In method 1.
try
Response.End();
afterResponse.BinaryWrite(_excuteGetDocumentResult);