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

前端 未结 16 996
一生所求
一生所求 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 10:43

    It's better to let the ContentPage notify the MasterPage. That's why the ContentPage has a Master Property and MasterPage does not have Child property. Best pratice in this is to define a property or method on the MasterPage and use this through the Master property of the ContentPage.

    If you use this technique it's best to explicitly specify the classname for the MasterPage. This makes to use the MasterPage in the ContentPage.

    Example:

    //Page_Load
    MyMaster m = (MyMaster)this.Master;
    
    m.TellMasterWhoIAm(this);
    

    Hope this helps.

提交回复
热议问题