Every web project requires some standard way of returning typical information and error reporting feedback to the user.
A common method is to reserve some portion of the screen, near the top under an application banner, near the submit controls or some other arbitrary combination. To preserve on screen real estate, some developers create collapsable sections or popup windows. I have been using Eeeksoft's popup window control as an easy way of displaying information for some time now. Eeeksoft's popup window control provides an Exchange-like feel for messaging and preserves valuable on screen real estate. And the best part is it's free!
You can read Thomas Petricek's original article here or check out Eeeksoft's website here.
I’ve created a simple routine which takes in a pages particular popup window and displays information messages using a blue color scheme which will dissapear after 5 seconds and displays error messages using a red color scheme with no timeout.
Now on to the implementation...
Once you've added a reference to the control…
EeekSoft.Web.PopupWin.dll
.. you can drag and drop a popup window onto your web page from the toolbar. It doesn’t really matter where you place it since it’s going to be invisible anyway. When it appears, by default it will show up as a popup window in the lower right hand side of the screen. Drag/Dropping the control onto the page renders the prefix code…
<!-- Popup.aspx -->
<%@ Register TagPrefix="cc1" Namespace="EeekSoft.Web" Assembly="EeekSoft.Web.PopupWin" %>
…and adds the following instance…
<cc1:popupwin id="popupWin" runat="server" visible="False"
colorstyle="Blue" width="230px" height="100px" dockmode="BottomLeft"
windowscroll="False" windowsize="300, 200" />
…finally, add this code to a utility class for your web project (e.g. WebUtility class in the AppCode folder):
public static void ShowMessages(EeekSoft.Web.PopupWin PopupWin1, Page P)
{
//Display Error Message
if ((P.Session["InfoMessage"] == null) && (P.Session["ErrorMessage"] == null))
{
PopupWin1.Visible = false;
}
if (P.Session["ErrorMessage"] != null)
{
PopupWin1.Message = P.Session["ErrorMessage"].ToString();
PopupWin1.Title = "Error Window";
PopupWin1.Text = P.Session["ErrorMessage"].ToString();
PopupWin1.ColorStyle = EeekSoft.Web.PopupColorStyle.Red;
PopupWin1.Visible = true;
PopupWin1.HideAfter = -1;
PopupWin1.PopupSpeed = 1;
P.Session["ErrorMessage"] = null; //clear message after read
}
else //display info message if there was no error
{
//Display Info Message if there is one
if (P.Session["InfoMessage"] != null)
{
PopupWin1.Message = P.Session["InfoMessage"].ToString();
PopupWin1.Title = "Information Window";
PopupWin1.Text = P.Session["InfoMessage"].ToString();
PopupWin1.ColorStyle = EeekSoft.Web.PopupColorStyle.Blue;
PopupWin1.Visible = true;
PopupWin1.HideAfter = 5000;
P.Session["InfoMessage"] = null; //clear message after read
}
}
} //ShowMessages
You can now happily code your messages using this simple procedure. Set information messages into the session variable “InfoMessage”, and set error messages into the session variable “ErrorMessage”. Call “ShowMessages” to display the popup window with your message on the screen. Include the call to ShowMessages in Page.Load on every page to report basic information and error messages when errors occur from other pages redirecting to your target page. Here are some examples:
Example 1. Let’s say you have a list product page which displays a list of all projects. The user attempts to edit one but the edit page returns to the list page when the product is not found. This happens when another user deletes the product for example. All you need to do to get the message from the edit page to display on the list page is include the showmessages call on page load.
ShowMessages(EeekSoft.Web.PopupWin PopupWin1, Page P)
To store the message for later retrieval from the edit page add:
Session[“ErrorMessage”] = “Unable to edit product!”;
Example 2. Let’s say you want to show either a success message or an error message when saving changes to a product. You add code like the following:
protected SaveProduct()
{
string errmsg = "";
string infomsg = "";
try
{
Product.Save();
infomsg = "Product Saved!";
}
catch (Exception ex)
{
errmsg = "Error trying to save product: " + ex.Message;
}
if (errmsg.Length > 0)
{
Session["ErrorMessage"] = errmsg;
WebUtility.ShowMessages(PopupWin1, Page);
}
if (infomsg.Length > 0)
{
Session["InfoMessage"] = infomsg;
response.redirect("ProductList.aspx", true);
}
}
Print | posted on Sunday, April 09, 2006 12:41 PM