How to determine which Child Page is being displayed from Master Page?

前端 未结 16 690
一生所求
一生所求 2021-02-02 10:26

I\'m writing code on the master page, and I need to know which child (content) page is being displayed. How can I do this programmatically?

16条回答
  •  执念已碎
    2021-02-02 11:01

    You can check the page type in the code-behind:

    // Assuming MyPage1, MyPage2, and MyPage3 are the class names in your aspx.cs files:
    
    if (this.Page is MyPage1)
    {
      // do MyPage1 specific stuff
    }
    else if (this.Page is MyPage2)
    {
      // do MyPage2 specific stuff
    }
    else if (this.Page is MyPage3)
    {
      // do MyPage3 specific stuff
    }
    

提交回复
热议问题