Solved

c# event : publish and subscribe

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

11 Experts available now in Live!

Get 1:1 Help Now