I have a aspx page that calls a long-ish running piece of code. My intent was to launch a modal popup with some verbiage or a hourglass-ish animation. Once the long running piece of code finished, the popup would close. Well... I can't get it to work.
Here is a dummy page that demonstrates the issue:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title><link href="StyleSheet1.css" rel="stylesheet" /></head><body><form id="form1" runat="server"><asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager><div><div style="width:500px;margin-left:auto;margin-right:auto;height:300px;background-color:#f5f5f5;text-align:center;"><h1>This is my neat div</h1><p><asp:Button ID="btnPopup" runat="server" Text="Pop" OnClick="btnPopup_Click" /></p></div></div><!--------------------------------------------------><button id="trgButton" runat="server" style="visibility: hidden;" /><asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="popupBackground" TargetControlID="trgButton" PopupControlID="popup" ></asp:ModalPopupExtender><asp:Panel ID="popup" runat="server" CssClass="popup"><p>whoo hoo i'm a popup</p></asp:Panel></form></body></html>
And here is the codebehind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Runtime.Remoting.Messaging;
using System.Diagnostics;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
public delegate void ShowPopupDelegate();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPopup_Click(object sender, EventArgs e)
{
ShowPopupDelegate s = new ShowPopupDelegate(ShowPopup);
s.BeginInvoke(new AsyncCallback(PopupComplete), s);
ModalPopupExtender1.Show();
}
private void ShowPopup()
{
for (int i = 1; i <= 10; i++)
{
Debug.WriteLine(Convert.ToString(i));
Thread.Sleep(1000);
}
}
private void PopupComplete(IAsyncResult ar)
{
Debug.WriteLine("Closing the popup");
ModalPopupExtender1.Hide();
}
}
}The popup shows just fine, and the callback PopupComplete runs and the code processes, but the popup never closes.