How to call aspx function from ascx without creating an instance of aspx page

I am using an ascx page as a popup in my aspx page. I am able to call any ascx function in my aspx page like this:

ASCX PAGE.Function()

But now I want to call aspx file functions from my ascx file and for that I have to create an instance of aspx file eg:

AspxPage af = new AspxPage ()
af.Function()

But I can't achieve my goal through this method, I want to call the function without creating a new instance.

Please guide me. Thank you. I am working in C# visual studio 2017

1 answer

  • answered 2018-11-08 08:33 SazooCat

    (1) Make sure the page inherits from a common class (MySpecialPageClass) they can both reach (this class should itself inherit from your usual base page class) (2) Add the methods to be exposed to the controls onto that class, make them public (MySpecialFunction). (3) In the control you'll need to do your own "IWantToCallThePageFunctionNowMethod" (pseudo code, not for copy+paste, you haven't indicated if you're working in c# or vb.net)

    function IWantToCallThePageFunctionNowMethod()
    {
        object thePage = this.Page
        if (checkTypeOfPageIsRightClass(thePage))
        {
            MySpecialPageClass theRightPage = (MySpecialPageClass)thePage
            theRightPage.MySpecialFunction(myParameter)
        }
    }