我有ASP.NET服務器與aspx頁面。 它通過點擊按鈕來製作適用於文件的操作。 我想告訴客戶「請等待行動運行」。 當動作完成,我想告訴大家完成客戶端的,回去我們是之前(與按鈕的頁面)什麼是最簡單的方法來創建「請稍候」或類似的東西在ASP.NET
服務器端ASPX頁面:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(Button1);
}
protected void Button1_Click(object sender, EventArgs e)
{
//FindControl(UpdateProgress1.ID).Visible = true;
Thread.Sleep(2000);
//FindControl(UpdateProgress1.ID).Visible = false;
UpdateProgress1.Attributes.Add("style", "display:none");
l1.Attributes.Add("style", "display:none");
//l1.Visible = false;
sendBackToUser();
}
private void sendBackToUser()
{
FileInfo file = new FileInfo(@"C:\F\f.xlsx");
if (file.Exists)
{
//Response.Clear();
//Response.ClearHeaders();
//Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + @"C:\F\f.xlsx");
//Response.AddHeader("Content-Type", "application/Excel");
//Response.ContentType = "application/vnd.xlsx";
//Response.AddHeader("Content-Length", file.Length.ToString());
//Response.WriteFile(file.FullName);
//Response.End();
}
else
{
Response.Write("This file does not exist.");
}
}
}
}
客戶端方:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="ShowProgress()"/>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" style="display:none" runat="server" >
<ProgressTemplate>
The report is creating please wait...
</ProgressTemplate>
</asp:UpdateProgress>
</form>
<asp:Label runat="server" ID="l1" style="display:none">The report is creating please wait... </asp:Label>
<script type="text/javascript">
document.getElementById('<% Response.Write(l1.ID); %>').style.display = "none";
document.getElementById('<% Response.Write(UpdateProgress1.ClientID); %>').style.display = "none";
function ShowProgress()
{
document.getElementById('<% Response.Write(l1.ID); %>').style.display = "inline";
document.getElementById('<% Response.Write(UpdateProgress1.ClientID); %>').style.display = "inline";
}
</script>
</body>
</html>
nothong ????? :( – hedo
冷靜下來,我在我的問題上等了20個小時...... 20分鐘回答,我想說,是相當不錯的迴應時間。 – Ortund
男人如果我不會很快完成我會被解僱 – hedo