User controls are being used more and more now in asp.net web sites. Sometimes you may need to call a method from it’s parent page. A nice quick way of doing this is to use Reflection. The method on the parent page must be declared public!
‘***Parent Page***
Public Sub HelloWorld()
Response.Write(“Hello World”)
End Sub
‘***User Control***
Me.Page.[GetType]().InvokeMember(“HelloWorld”, System.Reflection.BindingFlags.InvokeMethod, Nothing, Me.Page, New Object() {})
I find this technique useful in asp.net applications where i may need to dynamically update controls in parent pages from user controls.
Leave a reply