Solved

c# event : publish and subscribe

Posted on 2014-02-14
4
52 Views
Last Modified: 2016-06-16
I am trying to setup event in the server side, so when request coming, i register an event, and from other places i can subscribe to this event, say certain properties change, i want to raise or execute the event. Is it something possible in asp.net (c#)?  So similar to what JS has, publish an event, and subscribe from diff places.
0
Comment
Question by:johndenny
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39860137
Yes you can.

Essentially you can create a class that inherits from a standard control.  

public class MyUserControl : UserControl
{
   //this allows you to "publish" the event
    public delegate void onMyEvent(int AParam);
    public event onMyEvent MyEvent;
 
    public MyUserControl()
    {
          //subscribe to the event
          MyEvent += MyEventHandler;
    }

   // this occurs when the event happens
    public void MyEventHandler(int Param)
    {
                // do something
    }

}
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 41655414
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question