Listing all nested user controls from a master page on page load
On page load is there a way to enumerate all the nest user controls for that specific page load?
I'd like to be able to enumerate all the user controls that implement an interface, and call the interface method for the controls before asp.net passes control to thier page_load events.
The proble开发者_开发知识库m is from the master page level, any page in the app could be loading, and each of them could have any random user control, and I need the type reference to determine if they implement the interface, and to call the method.
Does anyone have any ideas?
Would something like this work?
void ProcessControls(Control control)
{
if(control is IMyInterface) //whatever your interface name is
{
(control as IMyInterface).MethodName();
}
foreach(Control child in control.Controls)
{
ProcessControls(child);
}
}
精彩评论