2017-07-06 34 views
0

我有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> 
+0

nothong ????? :( – hedo

+0

冷靜下來,我在我的問題上等了20個小時...... 20分鐘回答,我想說,是相當不錯的迴應時間。 – Ortund

+0

男人如果我不會很快完成我會被解僱 – hedo

回答

0

使用更新面板:

<asp:UpdatePanel runat="server" ID="UpdatePanel1"> 
    <ContentTemplate> 
     <!-- Your page markup goes here --> 
    </ContentTemplate> 
</asp:UpdatePanel> 

添加更新進度控制給你「請稍候」位

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" 
    DisplayAfter="10"> 
    <ProgressTemplate> 
     <asp:Panel ID="panProcessing" runat="server" CssClass="processing"> 
      <asp:Image ID="imgProcessing" runat="server" ImageUrl="~/Images/processingsmall.gif" 
       AlternateText="Processing" /><br /> 
      <br /> 
      <strong>Processing...</strong> 
     </asp:Panel> 
    </ProgressTemplate> 
</asp:UpdateProgress> 

,可隨時更換<asp:Panel與任何你想要的的UpdateProgress但本質上,如果操作時間長於DisplayAfter時, UpdateProgress將在頁面上顯示其內容。

這通常會顯示爲包含該消息的頁面內容上方的模式窗口,但您可以根據自己的喜好進行設置。

問題是,ASP負責這裏的繁重工作。

+0

非常感謝。那就是在運行時改變一個文本內部的內容? – hedo

+0

在這個例子中,它就是在這個例子中,我們可以嘗試幫助解決特定的問題。這個動畫表示系統很忙,你可以編寫一些JavaScript來定位一個標籤,並在那裏改變文本,但這完全是另一個問題(圍繞網絡應該有很多例子)去做) – Ortund

+0

我無法理解如何使用它... – hedo

相關問題