Wednesday, November 28, 2007

Have a child trigger a method in its parent

Often you'll want to have a child object trigger some method in its parent. For example, you'll click a user control, but want that to change something in the parent control. .Net 2.0 makes it very easy to do this. In .Net 1.1 (at least to my knowledge), this required a bunch of steps. Now, you can just add two lines in the object (declare a delegate, and then create an instance of that), and then use just one line in that object's consumer to specify the method to-be-called. In this case, we create an object "MyObject", with an event to be