Still a bit new to c# and I’m in need of some pointers in the right direction with this..
I want build a notification system in C#/Asp.net that will allow different methods all over the site to add messages and message types to some static list that can be looped through on the next page load. It would be similar to how stack overflow does the banner notifications for achievements on each page load (e.g. “you earned x badge”, you earned y badge”). Any idea how I might expose some global method that others could just go message.add(‘message’, ‘message type’) with?
Edit:
It’s been suggested that I use Session.Add("Notificiations", myList); to store the messages.
How/where would I go about initializing that “Notifications” list then do list.add() everywhere else?
You can write a class like this (I don’t have any IDE near me, so I hope the code will compile):
To add a message, you would do:
(These messages are stored in the session, meaning user specific);
Let’s assume you have literal in your masterpage, where you want to display your messages:
In your MasterPage you would add the OnInit Eventhandler:
This should give you a basic overview, how you can store and display the messages. Of course you can adjust this code, either by adding a method for deleting messages, or nice client side effects (like the notifications here on StackOverflow. To find out how that is done, you can use the search. It has been discussed here several times)
I hope this helps you.