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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<Title>Copying Event</Title>
<! ----- dynamically filled META REFRESH element ----->
<Meta id="mtaRefresh" runat="server" />
</head>
<Body>
<form id="frmMain" runat="server">
<! ----- "please wait" display ----->
<Center>
<div id="divWait" Visible="false" runat="server"><b>Processing, please wait...</b></div>
</Center>
</form>

</Body>
</html>

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;
}
else
{

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!!

Comments

Post a Comment

Popular posts from this blog

The key specified to compute a hash value is expired, only active keys are valid.

IFD Implementation for custom web pages and Anonymous Access

Using CRM Services to create or update records in large numbers