What is the relationship between the content page and the main page in terms of OOP?

What is a class relationship? Can someone help explain the link between the content page and the main page in terms of OOP?

0
source share
3 answers

I assume that you are really asking, what is the relationship between the page and its main page in terms of programming? I answer that relationships are not what most people would prefer . You might think that MasterPage contains a page because, looking at the html markup and ContentPlaceHolders, the html elements of the MasterPage end with the contents of the html elements on the page.

In fact, relationships are the other way around. The page belongs to the master page. The PreInit method on the page allows you to change the MasterPage.

The best way to describe what will happen next is for the Page to be wrapped in MasterPage . After the PreInit event of the content page, but before its Init event, the contents of the MasterPage are inserted in and around the asp: Content blocks in accordance with the position of the ContentPlaceHolders on the MasterPage.

Typically, event handlers on a page are executed up to those on MasterPage, which are processed as a control that has been introduced in and around the page.

You can see it in this > Tim Mount

Extract:

Page Start OnLoad(EventArgs e) Page Page_Load(object sender, EventArgs e) Page End OnLoad(EventArgs e) MasterPage Start OnLoad(EventArgs e) MasterPage Page_Load(object sender, EventArgs e) MasterPage End OnLoad(EventArgs e) UserControl Start OnLoad(EventArgs e) UserControl Page_Load(object sender, EventArgs e) UserControl End OnLoad(EventArgs e) CustomWebControl Start OnLoad(EventArgs e) CustomWebControl End OnLoad(EventArgs e) 
+1
source

Your content page inherits from the base content class. Your "MasterPage" is inherited from the "base main page" class. In your content class, you define the relationship between your content page and the main page. Base classes handle basic plumbing between them.

0
source

The main page inherits from Sytem.Web.UI.MasterPage, and the page inherits from System.Web.UI.Page

But think of MasterPage as a type of control.

If your question is about talking to another, then there are many methods for this.

Using the directive <%@ MasterType VirtualPath="~/templates/Base.master" %> or <%@ MasterType TypeName="SomeNamespace.SomeMasterPageBaseClass" %> can set up strong typing between your content page and the main page.

If you are dealing with nested master pages, you can also use <%@ Reference VirtualPath="~/templates/base.master" %>

A good description of complex interactions can be found here:

http://www.odetocode.com/articles/450.aspx

0
source

Source: https://habr.com/ru/post/1335871/


All Articles