Solved

c# event : publish and subscribe

Posted on 2014-02-14
4
43 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now