button放在updatepanel中不能下载文件

wanglinlin0204 2015-12-10 09:24:06
前台代码
<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server" style=" border:none">
<ContentTemplate>
<asp:Button ID="btn_DownAllFile" runat="server" Text="下载所有文档"
onclick="btn_DownAllFile_Click" />
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
文件压缩中...
</ProgressTemplate>
</asp:UpdateProgress>
后台
protected void btn_DownAllFile_Click(object sender, EventArgs e)
{
string XMMC = DAO_Project.getProjectName(_urlParam_XMID);
string FileToZip = Server.MapPath("~/upload/" + XMMC);//被压缩的文件
string ZipedFile = Server.MapPath("~/upload/Temp/" + XMMC + ".zip");//压缩后的文件
bool flag = ClassZip.Zip(FileToZip, ZipedFile, 4);
if (flag)
{ //下载
Tools_FileDownload.downFile(this, "~/upload/Temp/" + XMMC + ".zip" , XMMC+".ZIP"); //运行到这步时出错

}
不能弹出下载框,提示错误
Microsoft JScript 运行时错误: Sys.WebForms.PageRequestManagerParserErrorException: 未能分析从服务器收到的消息。
...全文
112 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanglinlin0204 2015-12-10
  • 打赏
  • 举报
回复
本来是没错的。用ProgressTemplate主要是因为压缩时间有点长。然后用了这个下载就没反应了
wanglinlin0204 2015-12-10
  • 打赏
  • 举报
回复
或者大家有没有什么别的办法,压缩时需要十几秒钟,希望给用户一点提示,不然以为页面没反应
正怒月神 2015-12-10
  • 打赏
  • 举报
回复
是不是路径错了?
abz7676 2015-12-10
  • 打赏
  • 举报
回复
楼上我给你的例子是 多文件压缩打包下载 的例子。
abz7676 2015-12-10
  • 打赏
  • 举报
回复
试试换一种思路。 首先需要Ionic.Zip.dll 页面前台


<body>
<form id="form1" runat="server">
<p>
    <asp:Button ID="PackDown" runat="server" Text="打包下载" OnClick="PackDown_Click" /></p>
<asp:GridView ID="GridView1" runat="server" Width="500px"
    CellPadding="8" CellSpacing="1">
    <Columns>
        <asp:TemplateField HeaderText="" InsertVisible="False">
            <ItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" />
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="文件列表" InsertVisible="False">           
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
</form>
</body>

页面后台CS代码:


void BindFilesList()
        {
            string strSql = "select Name from tableC";
            DataTable dt = m_db.ExecuteDataTable(strSql);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        protected void PackDown_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType = "application/zip";
            Response.AddHeader("content-disposition", "filename=DotNetZip.zip");
            using (ZipFile zip = new ZipFile(System.Text.Encoding.Default))
            {
                foreach (GridViewRow gvr in GridView1.Rows)
                {
                    if (((CheckBox)gvr.Cells[0].Controls[1]).Checked)
                    {
                        zip.AddFile(Server.MapPath("SoftwareDownload/") + (gvr.Cells[1].Controls[1] as Label).Text, "");
                    }
                }
                zip.Save(Response.OutputStream);
            }
            Response.End();
        }

重点参考后台CS里的PackDown_Click方法

110,552

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧