Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6050797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:43:43+00:00 2026-05-23T07:43:43+00:00

Still a bit new to c# and I’m in need of some pointers in

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:43:44+00:00Added an answer on May 23, 2026 at 7:43 am

    You can write a class like this (I don’t have any IDE near me, so I hope the code will compile):

    public class MessageHelper
    {
        protected const String sessionName = "messages_session";
        public List<String> Messages 
        {
            get 
            {
                List<string> list;
                if (Session[sessionName] != null)
                {
                    list = (List<string>)Session[sessionName];
                }
                else 
                {
                    list = new List<string>();
                }
                Session[sessionName] = list;
                return list;
            }
            set 
            {
                Session[sessionName] = value;
            }
        }
    
        public void AddMessage(String message) 
        {
            List<String> list = this.Messages;
            list.Add(message);
            this.Messages = list;
        }
    
    }
    

    To add a message, you would do:

    MessageHelper messageHelper = new MessageHelper();
    messageHelper.AddMessage("hello world");
    

    (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:

    <asp:Literal ID="litMessages" runat="server" />
    

    In your MasterPage you would add the OnInit Eventhandler:

    protected override void OnInit(EventArgs e)
    {
      MessageHelper messageHelper = new MessageHelper();
      String output = string.Empty;
      foreach(String message in messageHelper.Messages)
      {
        output += String.Format("{0}<br />", message);
      }
      this.litMessages.Text = output;
    
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Still a bit new to Linq. This is driving me nuts. I want to
Are pointers on a 64-bit system still 4 byte aligned (similar to a double
I'm still a bit new to Python, but, I feel really stupid right now
I am a little bit new to ASP.NET MVC, after searching I still have
I might be approaching this problem completely wrong, but I'm still a bit new
A bit new to this whole web development thing still. This question will be
I'm still a bit new to git, and I use gitg to visualize trees.
I am still a little bit new to C# and I was wondering how
I'm still relatively new to hadoop, and I've been learning a bit about it
still a bit of a n00b on SharpSVN, I'm looking to get some simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.