How do I reference an ASP.net MasterPage from App_Code

后端 未结 3 1377
暖寄归人
暖寄归人 2020-12-18 10:16

I\'m working on a .net 3.5 site, standard website project.

I\'ve written a custom page class in the sites App_Code folder (MyPage).

I also have a master page

3条回答
  •  一生所求
    2020-12-18 10:40

    I realise there are already accepted solutions for this, but I just stumbled across this thread.

    The simplest solution is the one listed in the Microsoft website (http://msdn.microsoft.com/en-us/library/c8y19k6h.ASPX )

    Basically it says, your code will work as-is, if you include an extra directive in the child page aspx:

    <%@ MasterType VirtualPath="~/MyMaster.Master" %>

    Then you can directly reference the property in the base MyPage by:

      public string PageID
      {
            set
            {
                Master.PageID = value;
            }
            get
            {
                return Master.PageID;
            }
        }
    

提交回复
热议问题