ASP.Net custom controls, child events and pain

 As you probably can tell I’ve been working on integrating Reporting Services within our ASP.Net website. A part of this integration is creating an ASP.Net custom control that will easily render a report from a page. Calling the Reporting Server web service is a snap and encapsulating this in a control is not a problem since I’ve had some experience with server controls (and yes they can be a big pain in the rear). I added a couple of LinkButtons to the control allow the user to export the report. But low and behold the Click events on the buttons wouldn’t fire. Dazed, I checked up on event bubbling and the IPostBackEventHandler but no dice. Then, I ran across a post titled “No events are fired in child control” in the microsoft.public.dotnet.framework.aspnet.buildingcontrols (say that five times fast) newsgroup. In a reply to this post Jeffrey Tan of Microsoft posted this nugget:

“Acutally, in Composite Control, if you want to hook the child controls’ event, you must implement the system.Web.UI.INamingContainer interface. It will provide you the unique names in the hierarchical tree of controls. If you do not implement this interface, asp.net model will not associate the event handler well.”

Nice. I added the one line of code and everything worked as advertised. Order is restored to the world

Now Playing: Pigeon John – Nothing Without You