我正在寻找某种行为,其中 ModalPopup 为要下载的文件建议一个(业务规则驱动的)文件名。
如果用户单击确定,则文件已下载,并且弹出窗口应关闭。取消只是关闭它。这都是由后面的代码驱动的:
protected void ExportPromptOkButton_Clicked(object sender, EventArgs e)
{
string path = MapPath(ExportPromptPanelFileName.Text);
WriteExport(path);
ExportPromptModalPopupExtender.Hide();
this.SendFile(path, "text/plain");
}
//...
public static void SendFile(this Page webPage, string filepath, string contenttype)
{
webPage.Response.AddHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(filepath));
webPage.Response.ContentType = contenttype;
webPage.Response.WriteFile(filepath);;
webPage.Response.End();
}
问题是Response.End();
杀死所有动作(好吧,应该如此),所以模态窗口本身不会关闭。
什么是正确的方法?我正在考虑使用 iframe 并调用它Response
来发送文件,但我想确认这是否合适或者是否有更好的东西。
ASPX 声明:
<ajaxToolkit:ModalPopupExtender
runat="server"
ID="ExportPromptModalPopupExtender"
BackgroundCssClass="modalBackground"
TargetControlID="ExportButton"
PopupControlID="ExportPromptPanel"
PopupDragHandleControlID="ExportPromptPanelHeader"
CancelControlID="ExportPromptCancelButton"
Drag="true">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="ExportPromptPanel" runat="server" CssClass="popupConfirmation" style="display: none;">
<div class="popupContainer" style="width:300px">
<div class="popupHeader" id="ExportPromptPanelHeader">
<div class="popupHeaderLeft">Export</div><div class="popupHeaderRight"></div>
</div>
<div class="popupBody">Export under the following name:<br />
<asp:TextBox ID="ExportPromptPanelFileName" runat="server" MaxLength="60" Width="230px"></asp:TextBox></div><div class="popupButtons">
<asp:Button ID="ExportPromptOkButton" runat="server" Text="Ok" OnClick="ExportPromptOkButton_Clicked" />
<asp:Button ID="ExportPromptCancelButton" runat="server" Text="Cancel" />
</div>
</div>
</asp:Panel>