I am building ASP.NET 2.0 websites and currently I some home grown assemblies for a DAL, some business objects and other assorted shared stuff. I've put together a basic set of objects to handle messages to the UI (i.e. errors and other status messaging). It consists of:
StatusMessage which has a text property and a color property to describe the message to display. It also has a static Send method which creates an instance of itself and puts it in a Session variable.
StatusMessageDisplay which is basically a Label object with the Refresh method overridden to grab the StatusMessage from the session, clear the Session variable and display the message.
Overall this has worked fairly well. However, there are a few things I don't like about it:
It can only handle a single message at a time, if two messages are sent before they are displayed, the first is lost. I could make a list of messages to display but I'm not sure I want to start building lists in the Session object.
It's tied to Session and therefore HttpContext. I try not to put much into the Session object and HttpContext is difficult to work with for testing. Currently I'm wrapping HttpContext in another object I can mock for testing.
In my current implementation, if a message is passed from an AJAX request the message displays late (next sync'd request) since the StatusMessageDisplay control is not AJAX aware/triggered.
Before I start building on what I have to fix these issues I would like to find out what others have found useful for doing this. What I would really like is something that behaves like the flash object in Rails or maybe a better alternative?