ASP.Net and GetType()

后端 未结 4 1939
花落未央
花落未央 2021-01-12 18:44

I want to get a type of a \"BasePage\" object that I am creating. Every Page object is based off BasePage. For instance, I have a Login.aspx and in my code-behind and a clas

4条回答
  •  执笔经年
    2021-01-12 19:36

    page.GetType().BaseType, it has been said before, but let me elaborate as to why.

    Aspx pages inherit from their code-behind pages, meaning that the inheritance hierarchy looks like this:

    ...
    Page
    BasePage
    Login
    ASP_Login
    

    Where the top is the parent and the bottom is the child.

    This allows your code behind to be accessible from the aspx page, without requiring all of the generated code related to your actual aspx page to be copied into the base class page.

提交回复
热议问题