Monday, December 14, 2009

Custom message on the web page during server side processing

Recently, while working on MS CRM based solution, I encountered a typical aspx page loading issue. I had added a button in ISV config of my custom entity, which would load an aspx page. There was a code block on the page load which would fetch records from the server and display them on the page. The processing time increased enormously since there were a lot many records to retrieve and hence, the page loaded real slow :(. And while the user kept waiting for the page to show up, there was really no intimation to the user that the page processing is going on and the page would finally appear :)

I found a very simple solution to this problem through Meta tag usage on the page. Below is a quick sample showing a custom message on the web page while some processing happens at the server side. Though there were other approaches also for this problem, I found this the simplest and easiest to implement.

Follow the below mentioned steps to use the Meta refresh tag.

1. Add the Meta refresh Tag in the HTML code for the web page in the header tag of the page.

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<Title>Copying Event</Title>
<! ----- dynamically filled META REFRESH element ----->
<Meta id="mtaRefresh" runat="server" />
<form id="frmMain" runat="server">
<! ----- "please wait" display ----->
<div id="divWait" Visible="false" runat="server"><b>Processing, please wait...</b></div>


Also Notice that a div tag is added in the body section of the page that would display the required “Processing, please wait” message to the user.

2. On the server side code of the page, in Page_load event, add the following code to refresh the URL.

protected void Page_Load(object sender, EventArgs e)
if (Request.QueryString["doAction"] == null)
string sRefreshURL = Request.Url.ToString();
// use META REFRESH to start loading next page
mtaRefresh.Attributes.Add("http-equiv", "refresh");
mtaRefresh.Attributes.Add("content", "0;url=" + sRefreshURL + "&doAction=1");

divWait.Visible = true;

divWait.Visible = true;
divWait.InnerText = "Done";

That’s it!! This code block would ensure that the page displays a wait message till the page load event is being processed. Happy Coding!!

1 comment: