什么是在ASP.NET

时间:2017-07-06 10:37:55

标签: c# asp.net excel web

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

1 个答案:

答案 0 :(得分: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>

您可以将UpdateProgress中的<asp:Panel替换为您想要的任何内容,但实质上,如果操作时间超过DisplayAfter,则UpdateProgress将在页面上显示其内容。

这通常会显示为包含邮件的页面内容上方的模式窗口,但您可以根据需要设置样式。

关键在于ASP在这里负责繁重。