艺海无涯,学无止境。欢迎一起探讨技术和人生,了解我

FineUI 响应确定按钮(点击确定按钮后,下载文件)


<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" OnCustomEvent="PageManager1_CustomEvent" runat="server" />
<f:Button Text="操作(先弹出提示框,点击确定后下载文件)" runat="server" ID="btnOperation" OnClick="btnOperation_Click">
</f:Button>
</form>
</body>

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

}
}

protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (e.EventArgument == "Confirm_OK")
{
// 非AJAX回发
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=alert_download.txt");
Response.ContentType = "text/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Write("这是下载文件的内容!");
Response.End();
}
else if (e.EventArgument == "Confirm_Cancel")
{
// AJAX回发
ShowNotify("点击了取消按钮!");
}
}

protected void btnOperation_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Confirm.GetShowReference("操作成功!点击确定按钮开始下载文件,点取消按钮弹出对话框",
String.Empty,
MessageBoxIcon.Question,
PageManager1.GetCustomEventReference(false, "Confirm_OK"), // 第一个参数 false 用来指定当前不是AJAX请求
PageManager1.GetCustomEventReference("Confirm_Cancel")));
}