ASP.NET User Control to Display Notifications (Info / Warning / Error Messages)
Modern Web applications need to have a way to inform the user about the result of their actions. For example if someone press the “Save” button, he or she should be notified with a message like “Document saved” or error message “Cannot save the document”. In addition some of the notifications are not too important and should be shown for a while and disappear automatically after few seconds.
To address this problem I recently designed a reusable ASP.NET user control (.ascx) which displays a list of messages in ASP.NET Web Forms application (like a MessageBox in desktop applications):
ErrorSuccessNotifier Web User Control
The Web user control “ErrorSuccessNotifier.ascx” consists of:
- API for adding notification messages which will be displayed the first time when the control is rendered:
- It supports 4 types of messages: Info, Success, Warning and Error messages.
- A static method to add a notification message which consists of text, type and auto-hide settings
- Images (for the icons)
- CSS styles (dynamically included on demand)
Ideally, the ErrorSuccessNotifier should be inserted in the master page (Site.master) of the ASP.NET Web Forms application and will display error and notification messages in all pages of the application (when such messages are assigned during the event handling C# logic).
Download the ErrorSuccessNotifier
Download the full C# source code of the ErrorSuccessNotifier Web user control: Error-Handler-Control-ASP.NET-by-Svetlin-Nakov.zip.