1

I am trying to indicate on my aspx page that it is processing the request. Maybe this isn't the best way to go about doing it. But I can't seem to find a another way to get this to work. I Hope what I'm trying to do makes sense. I appreciate any help and suggestions.

Anyway here is the ASPX code:

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="content">

<style type="text/css">
    #UpdatePanel1, #UpdatePanel2, #UpdateProgress1 { 
        border-right: gray 1px solid; border-top: gray 1px solid; 
        border-left: gray 1px solid; border-bottom: gray 1px solid;
    }
    #UpdatePanel1, #UpdatePanel2 { 
        width:200px; height:200px; position: relative;
        float: left; margin-left: 10px; margin-top: 10px;
    }
    #UpdateProgress1 {
        width: 400px; background-color: #FFC080; 
        bottom: 0%; left: 0px; position: absolute;
    }
</style>
    <div>
        <asp:ScriptManager ID="ScriptManager2" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
            <ContentTemplate>
                <%=DateTime.Now.ToString(CultureInfo.InvariantCulture) %> <br /> 
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:UpdateProgress ID="UpdateProgress1" runat="server">
            <ProgressTemplate>
                Archiving...
            </ProgressTemplate>
        </asp:UpdateProgress>
    </div>

<table cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <ul>
                <li>
                    <span>
                        <asp:ImageButton ID="ArchiveImageButton" runat="server" AlternateText="Archive Compliance"
                            ImageUrl="~/images/Icons/24/452-bank.gif" OnClick="Button_Click" ToolTip="Archive compliance results" />
                    </span>

                </li>
            </ul>
        </td>
    </tr>

And Here is the C# Code-Behind:

    private bool archiving;

    protected void Button_Click(object sender, EventArgs e)
    {
        archiving = true;
        WaitHandle wait = new EventWaitHandle(false, EventResetMode.AutoReset);
        ThreadPool.QueueUserWorkItem(state => btnArchive_Click(sender, e));
        ThreadPool.QueueUserWorkItem(sleepState => Sleep());
        ThreadPool.RegisterWaitForSingleObject(wait, delegate { WakeMeUp(); }, false, 9999999999999999, true);
    }

    private void WakeMeUp()
    {
        archiving = false;
    }

    private void Sleep()
    {
        while (archiving)
        {
            Thread.Sleep(1);
        }
    }

    protected void btnArchive_Click(object sender, EventArgs e)
    {
         //DO WORK
         ShowSuccessMessage("Compliance results have been archived.");
    }
4

1 回答 1

1

出于您的目的,听起来使用 JavaScript 显示叠加层会更容易。代码如下,这里是一个 jsFiddle 来演示。

<script type="text/javascript">
    showOverlay = function(){
        var overlay = document.getElementById("overlay");
        if (overlay){
            overlay.style.display = "block";
        }
    }     
</script>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClientClick="showOverlay();" />
<div id="overlay">
    <div id="wait-dialog">Please wait while the form processes...</div>
</div>

这是您需要的 CSS:

#overlay {
    display: none;
    position: absolute;
    left: 0;
    top: 0;
    background-color: #666;
    width: 100%;
    height: 100%;
    z-index: 100;
}
div#wait-dialog {
    margin: 0px auto;
    padding: 20px;
    text-align:center;
    width: 400px;
    min-height: 200px;
    background-color: #ccc;
}
于 2013-10-03T16:01:16.707 回答