Content Page Class Method Call from Home Page Class

I have a public method in my content page class, I want to call this method from the main page class
Thanks

+1
source share
3 answers

You can inherit your page from the base class. Then you can create a virtual method in your base class, which will be overridden on your page. Then you can call this virtual method from the main page as follows:

(cphPage.Page as PageBase).YourMethod();

Here is the identifier on the main page. is the base class containing the method . cphPage ContentPlaceHolder PageBase YourMethod

: , , YourMethod, .

+6

-

,

private object callContentFunction(string methodName, params object[] parameters)
{
    Type contentType = this.Page.GetType();
    System.Reflection.MethodInfo mi = contentType.GetMethod(methodName);
    if(mi == null)return null;
    return mi.Invoke(this.Page, parameters);
}

callContentFunction ( "myPublicMethodName", myParam1, myParam2...);

+3

:

  • <%@ MasterType VirtualPath="location of your masterpage" %> .aspx

  • MasterPage.

  • Master.functionName().

+2

All Articles