Introduction
This article will show how to render a 'please wait page' while the web server is performing a lengthy operation.
Background
Animated GIFs are a good way to show users that an application is busy. If you have ever tried to display an animated GIF using client side scripting on a user
initiated postback, you will know that the GIF is frozen at the first frame. This happens because IE shuts down the background thread while posting back.
The AJAX partial postback feature resolves the frozen animation issue, but does not work well if the page contains certain controls such as validators.
Using the code
The source code consists of a single class that I have named LongOperation
. This class is statically initialized with the URL of a 'long operation page' that will
be rendered to the web client while processing the lengthy operation. Three lines of code are needed to animate your lengthy operations as shown
in the btnDoOperation_Click
event handler below.
namespace ByteTec.OnSubmitAnimation.Demo {
public partial class LongOperationStart : System.Web.UI.Page {
static LongOperationStart() {
ByteTec.Web.LongOperation.LongOperationPageUrl =
ApplicationUrl + "/LongOperationAnimation.aspx";
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
btnDoOperation.Click += new EventHandler(btnDoOperation_Click);
}
void btnDoOperation_Click(object sender, EventArgs e) {
ByteTec.Web.LongOperation _longOperation =
new ByteTec.Web.LongOperation(this);
_longOperation.Begin();
System.Threading.Thread.Sleep(5000);
_longOperation.End("/LongOperationConfirmation.aspx");
}
private static string ApplicationUrl {
get {
if (HttpContext.Current.Request.Url.IsDefaultPort) {
return HttpContext.Current.Request.Url.Scheme + "://" +
HttpContext.Current.Request.Url.Host;
} else {
return HttpContext.Current.Request.Url.Scheme + "://" +
HttpContext.Current.Request.Url.Host + ":" +
HttpContext.Current.Request.Url.Port;
}
}
}
}
}