Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 15th, 2007, 02:30 PM
Registered User
 
Join Date: May 2007
Location: Vancouver, BC, Canada.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to forkbeard
Default Dynamically Altering a Child Control's Method

I'm building a generic template control in C#. Among other things, this control will enumerate all of its children, adding a method call to the child's changed event where applicable. Is it possible to alter an event at run time? Probably not eh?

Ok, so I just had a bit of an epiphany and realized that I don't need to add a method call but I'd still be interested to know how one could do this.

--
Shaun
 
Old May 15th, 2007, 06:30 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm not sure if this is what you are looking for but...

Certainly events can be wired up at runtime. Actually, that's the ONLY time they are wired up. The code usually looks something like this:

classInstance.SomeEvent += new EventHandler(MyMethodToHandleTheEvent);

The method signature of "MyMethodToHandleTheEvent" needs to match whatever the "EventHandler" delegate is expecting and "SomeEvent" must be of type "EventHandler" in order for that to pass compilation.

If you look in the code of any application that has event handling (web form, win form) you'll see this syntax in lots of places.

-Peter
 
Old May 15th, 2007, 07:13 PM
Registered User
 
Join Date: May 2007
Location: Vancouver, BC, Canada.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to forkbeard
Default

Thanks a bunch! I'll give that a try tomorrow at work.

--
Shaun




Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically created control's values to database saket123 ASP.NET 2.0 Basics 4 August 13th, 2008 12:49 AM
Altering a listbox from another form Firestorm9 C# 2005 1 July 9th, 2007 06:12 AM
how to make child dynamically gantait XSLT 1 February 23rd, 2007 06:29 AM
How to retrieve control's "Name" and "Value" in an niranjanshaiwale C# 0 September 27th, 2006 04:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.