C#ASP.NET代码后循环显示进度和状态当前记录

时间:2015-05-08 17:22:00

标签: c# jquery asp.net ajaxcontroltoolkit progress

我认为这可以通过Jquery或ASP.NET Ajax轻松实现,但却找不到解决方案或能够创建解决方案。 我接近以下但在循环期间无法将值返回到lblStatus。或者可能只使用Jquery和AJAX。

JQuery的

<script src="js/jquery-1.7.min.js" type="text/javascript"></script>
<script>
    function validateAdd() {
        var myExtender = $find('ProgressBarModalPopupExtender');
        myExtender.show();
        return true;
    }
</script>

HTML

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <ajaxToolkit:ModalPopupExtender ID="ProgressBarModalPopupExtender" runat="server" BackgroundCssClass="ModalBackground" BehaviorID="ProgressBarModalPopupExtender" TargetControlID="hiddenField" PopupControlID="Panel1" DynamicServicePath="" Enabled="True" />
    <asp:Panel ID="Panel1" runat="server" Style="display: none; background-color: #C0C0C0;">
        <p class="wait">Please wait!</p>
        <asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>
    </asp:Panel>
    <asp:HiddenField ID="hiddenField" runat="server" />
    <input type="submit" value="Process Records" id="process" causesvalidation="False" onclick="javascript: return validateAdd();" onserverclick="btnProcess_ServerClick" runat="server" />
</form>

然后在后面的代码中,在每个循环上执行循环和推送状态,然后隐藏进程对话框。如果我能更好地展示进展,只是试图显示当前的记录处理。

protected void btnProcess_ServerClick(object sender, EventArgs e)
{
    //Example Test Looping Through Slow Process
    string[] arr1 = new string[] { "record_one", "record_two", "record_three" };

    foreach( string s in arr1)
    {
            lblStatus.Text = "Processing.." + s;
            Thread.Sleep(2000);
    }
    ProgressBarModalPopupExtender.Hide();
}

0 个答案:

没有答案