G
Guest
Hello,
I have an asp.net web page (say page.aspx) which derives from a custom base
page object (CustomPage : BasePage : System.Web.UI.Page) Which has a method
called DoSomething(params). My web page contains a UserControl (say
Control.ascx).
In the control class, i want to call the DoSomething method. I cannot use
type cast since in fact the base class Page structure is a little more
complex (see bottom of post). Hence i cannot do:
CType(Me.Page, BasePage).DoSomething(params)
instead i use reflection
Me.Page.GetType().InvokeMember("DoSomething", BindingFlags.InvokeMethod,_
Nothing, Me.Page, New Object() {param})
'This is pretty much the same type of code used to call methods from a
master
'page in a UserControl (since master page's data type in not accessible
from a
'usercontrol)
In any .NET App or Web app, this works well. But for some reason, it doesn't
work in a UserControl. (This code works fine in the aspx code behind but not
in the ascx code behind).
In a UserControl's code behind, this throws a MissingMethodException
Anyone already experienced this issue?
What is very strange here is that the following code does work
Dim mi As Reflection.MethodInfo = Me.Page.GetType().GetMethod("DoSomething")
mi.Invoke(Me.Page, Reflection.BindingFlags.InvokeMethod, Nothing, New
Object() {param}, Nothing)
Thanks
Renaud
==============================
Base Class Page structure
Class FoundationBasePage : System.Web.UI.Page
Class FoundationBaseFirstPage : FoundationBasePage
Class FoundationBaseLastPage : FoundationBasePage
Class BasePage : FoundationBasePage
Class BaseFirstPage : FoundationBaseFirstPage
Class BaseLastPage : FoundationBaseLastPage
The method DoSomething is located in BasePage, BaseFirstPage and BaseLastPage
The UserControl may be used in pages inheriting from any of those three base
classes.
I have an asp.net web page (say page.aspx) which derives from a custom base
page object (CustomPage : BasePage : System.Web.UI.Page) Which has a method
called DoSomething(params). My web page contains a UserControl (say
Control.ascx).
In the control class, i want to call the DoSomething method. I cannot use
type cast since in fact the base class Page structure is a little more
complex (see bottom of post). Hence i cannot do:
CType(Me.Page, BasePage).DoSomething(params)
instead i use reflection
Me.Page.GetType().InvokeMember("DoSomething", BindingFlags.InvokeMethod,_
Nothing, Me.Page, New Object() {param})
'This is pretty much the same type of code used to call methods from a
master
'page in a UserControl (since master page's data type in not accessible
from a
'usercontrol)
In any .NET App or Web app, this works well. But for some reason, it doesn't
work in a UserControl. (This code works fine in the aspx code behind but not
in the ascx code behind).
In a UserControl's code behind, this throws a MissingMethodException
Anyone already experienced this issue?
What is very strange here is that the following code does work
Dim mi As Reflection.MethodInfo = Me.Page.GetType().GetMethod("DoSomething")
mi.Invoke(Me.Page, Reflection.BindingFlags.InvokeMethod, Nothing, New
Object() {param}, Nothing)
Thanks
Renaud
==============================
Base Class Page structure
Class FoundationBasePage : System.Web.UI.Page
Class FoundationBaseFirstPage : FoundationBasePage
Class FoundationBaseLastPage : FoundationBasePage
Class BasePage : FoundationBasePage
Class BaseFirstPage : FoundationBaseFirstPage
Class BaseLastPage : FoundationBaseLastPage
The method DoSomething is located in BasePage, BaseFirstPage and BaseLastPage
The UserControl may be used in pages inheriting from any of those three base
classes.