下载到CSV一个支持Ajax网页 [英] Downloading to CSV on an ajaxified page
问题描述
我有一个asp / vb.net的Web应用程序,并与该网站的其他部分保持一致,我使用AJAX和我的控制按钮,提高从ASCX事件。客户端点击下载按钮已经被用来处理帐户权限。
I have an asp/vb.net web app, and for consistency with the rest of the site, I am using AJAX and my control buttons raise events from an ascx. Client Click on the download button is already being used to handle account permissions.
我下载到CSV功能使用的Response.Write有一次我写的AJAX输出停止,虽然code仍是起火。
My download to CSV function uses response.write and once I wrote the AJAX the output stopped, though the code still fires.
目前我正在写另一个未ajaxed,空白ASPX做的Response.Write它正在以一个新的标签/窗口,通过启动脚本我的控制按钮寄存器打开。
Currently I am writing another un-ajaxed, blank aspx to do the response.write It is being opened in a new tab/window via a startup script my control button registers.
必须有一个更好的策略。有什么想法?
There has to be a better strategy. Any thoughts?
推荐答案
我不太明白你所说的一切,但是当我在过去所做的那样下载来自AJAX控件,我不得不设置下载按钮作为一个完整的回发的控制。您可以从ASPX / ASCX做到这一点,或者你可以以编程方式做到这一点是这样的:
I didn't quite understand everything you said, but when I've done downloads from AJAX controls in the past, I've had to set the download button as a full postback control. You can do this from the aspx/ascx, or you can do it programmatically like this:
// The export button needs to do a full postback, regardless of whether we're in an
// AJAX UpdatePanel.
var updatePanel = GetParentUpdatePanel();
if (updatePanel != null)
{
var scriptManager = ScriptManager.GetCurrent(Page);
if (scriptManager != null)
{
scriptManager.RegisterPostBackControl(exportButton);
}
}
...
[CanBeNull]
private UpdatePanel GetParentUpdatePanel()
{
Control parent = Parent;
while (parent != null)
{
if (parent is UpdatePanel)
{
return (UpdatePanel) parent;
}
parent = parent.Parent;
}
return null;
}
这篇关于下载到CSV一个支持Ajax网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!