I am developing a composite control for an ASP.NET application and just by chance initially developed the control to use an ITemplate to create its child controls. There will be a series of buttons within the child controls that are to be handled in the root control. I am using the OnBubbleEvent with CommandName/CommandArgument properties on the buttons to wire it all up. And everything worked great... until I changed the templates to controls.

When I converted the template to a Control and called Controls.Add(new ChildControl()) in my root control instead of InstantiateIn(this), event bubbling no longer works.

Any idea why?

(Everything, and I mean everything, else is the same.)

有帮助吗?

解决方案

Your composite control must implement INamingContainer interface in order to receive OnBubbleEvent calls. The CompositeControl class already implements this interface... in your case it stopped working not because of ITemplate thing, but because you changed inheritance from CompositeControl to Control.

See this: http://msdn.microsoft.com/en-us/library/system.web.ui.control.onbubbleevent.aspx

they say it there.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top