【发布时间】:2014-03-07 17:04:20
【问题描述】:
我的问题是,当我从对话框后面的代码中调用关闭对话框时,使用引用的 aspx 页面不会关闭。 如果我注释代码的响应传输文件部分,则对话框正确关闭,否则下载开始但对话框保持打开状态。 如果您有什么建议,请告诉我,谢谢!
ASPX 页面:
<%@ Page Async="true" AsyncTimeout="30" Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register src="CreateUI.ascx" tagname="CreateUI" tagprefix="uc1" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<%--JQuery--%>
<script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
<link href="Styles/jquery-ui-1.10.4.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$('#jobDone').dialog({
autoOpen: false,
draggable: true,
title: "Job completed",
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
});
function showDialog(id) {
$(function () {
$('#' + id).dialog("open");
return false;
});
}
function closeDialog(id) {
$(function () {
$('#' + id).dialog("close");
return false;
});
}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<!-- ScriptManager to manage UpdatePanel -->
<asp:ScriptManager ID="mainScriptManager" runat="server"></asp:ScriptManager>
<!-- CreateUI Component -->
<uc1:CreateUI ID="CreateUIForm" runat="server" />
<!-- Hidden Field to pass data -->
<asp:Table ID="TableMain" runat="server" CssClass="table">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell ID="TableCell1" runat="server">
<asp:HiddenField ID="UI_Paths" runat="server" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<!-- div linked to Jquery dialog -->
<div id='jobDone'>
<asp:UpdatePanel ID="UpdatePanelDownload" UpdateMode="Conditional" ChildrenAsTriggers="false" runat="server">
<ContentTemplate>
<asp:Label ID="LabelMessage" runat="server" Text="Operation ended successfully, do you want to download the produced files?</br></br>"></asp:Label>
<asp:Button ID="ButtonDownload" runat="server" Text="Yes" Width="50px" onclick="ButtonDownload_Click" />
<asp:Button ID="ButtonNo" runat="server" Text="No" Width="50px" OnClientClick="closeDialog('jobDone'); return false;" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
代码隐藏:
private void DownloadFile(object uiPaths)
{
UIGEN config = (UIGEN)System.Configuration.ConfigurationManager.GetSection("UIGENGroup/UIGEN");
string toPath = config.sharedPath;
if (!toPath.EndsWith(@"\"))
toPath += @"\";
string[] fileNamePaths = uiPaths.ToString().Split(new char[] { '*' });
string zipName = toPath + DateTime.Now.ToString().Replace("/", "_").Replace(":", "_").Replace(" ", "_") + ".zip";
SharpZipLib.CreateZip(zipName, null, fileNamePaths, SharpZipLib.FolderOffset.LastDirOnly);
try
{
FileInfo file = new FileInfo(zipName);
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\"");
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/x-zip-compressed";
Response.Flush();
Response.TransmitFile(file.FullName);
Response.End();
}
catch (System.Exception ex)
{
//To do ...Manage the error
}
//Delete zip from Server Shared Folder
if (File.Exists(zipName))
File.Delete(zipName);
}
protected void ButtonDownload_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
DownloadFile(UI_Paths.Values);
}
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), UniqueID, "closeDialog('jobDone');", true);
}
【问题讨论】:
标签: c# jquery asp.net dialog download