Raising Events

Sometimes you will want to raise events of your own from within your controls. For example, a validation control might raise an event to let its parent control know that it found an invalid element. Although not necessary for many kinds of controls and a bit more advanced, custom events can be a powerful tool. A simple example of raising an event and handling it from an ASP.NET page is really all that we have room for in this chapter, but it should give you an idea of how this works and get you started if you need to build an event-raising control of your own.

Just to keep things simple, we're going to add an event to our HelloPerson class that we used earlier in the chapter. We have decided that if this control's PersonName property ...

Get ASP.NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.