Com*_*ter 6 .net vb.net asp.net updatepanel http
下面的代码可以让我下载一个Word文档.....
Try
Response.BufferOutput = True
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/msword"
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=myfile.doc")
HttpContext.Current.Response.Write(s)
'HttpContext.Current.Response.End()
HttpContext.Current.ApplicationInstance.CompleteRequest()
HttpContext.Current.Response.Flush()
Catch ex As Exception
Response.Write(ex.Message)
End Try
Run Code Online (Sandbox Code Playgroud)
但是,只要我添加一个UpdatePanel - 它没有下载文件,没有生成错误?阅读后,我添加了一个触发器,其ControlID值设置为开始创建Word doc文件的按钮.我已经尝试了几种代码组合,但似乎没有任何效果.有关如何缩小范围的任何帮助?我也调试了,没有错误显示.我检查了我的下载文件夹 - 没有任何东西,尝试设置无缓存(Response.Cache.SetCacheability(HttpCacheability.NoCache)),并没有工作.一旦我删除UpdatePanel,那么一切似乎都有效?
<asp:UpdateProgress ID="ProgressUpdate" AssociatedUpdatePanelID="UpdatePanel1" runat="server">
<ProgressTemplate>
<img alt="progress" src="../images/loading.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="buttonDownloadFile" />
</Triggers>
<ContentTemplate>
..
Run Code Online (Sandbox Code Playgroud)
完全失去了这一个.任何人都可以建议解决方法或如何解决这个问题?
接受的答案是完全错误的.您需要使用scriptmanager注册控件.我在主页面中,这是我用来注册任何按钮以进行正确回发的代码.
private void MasterPageRegisterButtonForPostBack(Control bt)
{
MasterPage masterPage = Master;
if (masterPage is MainMaster)
{
var mainMaster = masterPage as MainMaster;
if (bt != null && mainMaster.MasterScriptManager != null)
{
mainMaster.MasterScriptManager.RegisterPostBackControl(bt);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我按以下方式工作:
在我的更新面板中,我配置了可能强制完整回发以使下载工作的控件。
(我也在使用母版页,这与 Steve 的解决方案相同,但将其注册在 aspx 中,而不是在后面的代码中)
<asp:UpdatePanel runat="server" ID="UpdatePanelDownload" UpdateMode="Conditional" ChildrenAsTriggers="True">
<ContentTemplate>
<asp:LinkButton ID="LinkButtonDownload" OnClick="Download_Click" runat="Server">Save XML</asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="LinkButtonDownlod" />
</Triggers>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
sh1*_*rts -6
UpdatePanel不支持文件上传或下载。有大量支持 ajax 的组件可以做到这一点,Google 是你的朋友。
编辑: -
一些例子: -
http://forums.asp.net/t/1076322.aspx?How+to+create+a+flipcart+like+panel+for+showing+products+in+gridview - 我喜欢这种方法,他使用注入一个 IFrame指向负责下载文件的页面的 JavaScript。在 UpdatePanel 内工作
http://encosia.com/ajax-file-downloads-and-iframes/ - 类似的方法
归档时间: |
|
查看次数: |
11063 次 |
最近记录: |