Use of ASP. NET master pages

Source: Internet
Author: User
Definition and description:

The master page isVs2005
One of the most important new features,Can be an applicationProgramCreate a consistent layout. A single master page can define the desired appearance and standard behavior for all pages (or a group of pages) in the application. Then, you can create various content pages that contain the content to be displayed. When a user requests a content page, these content pages are merged with the master page to combine the layout of the master page with the content of the content page for output.

The definition is too theoretical. Let's give an example to make it simple. For example, shopping bags in supermarkets are different from commodities in supermarkets, but one or more bags are printed with the logo of supermarkets. The combination of shopping bags and products is basically the same as that of the master page and content page. When creating a website, for example, the logo and footer of a webpage must be reused on multiple pages, you can place the content on the master page (shopping bag) so that multiple pages can share the content and make different content parts into content pages (products ), finally, fill different content pages in the master page.

The advantages of the master page are as follows:

(1) You can use the master page to process the general functions of the page in a centralized manner, so that you can update the page at only one location.

(2) You can easily create a group of controls andCodeAnd apply the results to a group of pages. For example, you can use a control on the master page to create a menu that applies to all pages.

(3) by allowing the display of placeholder controls, you can control the layout of the final page in details on the master page.

(4) The master page provides an object model that allows you to customize the parent page from each content page.

Use of the master page:

The usage of the master page is basically the same as that of a common page. You can place files or images, HTML and Web controls, and post-code. the master end cannot be directly viewed by the browser. It can only be viewed by other content pages.

Data Interaction Between the master page and the Content Page:

I found this part from the Internet and noted it down if it feels good.

(1) Use the content page control on the master page

Contentplaceholder1.findcontrol ("gv1") as gridview;

(2) Use the control on the master page on the Content Page

On the master page:
Public panel panelgv
{
Get
{
Return pnlgv;
}
}

(3) Functions of the content page called on the master page

On the master page:

Public Delegate void noargeventhandler ();
Public event noargeventhandler evt1;

// Call the content page function in a function:
{
If (evt1! = NULL)
Evt1 ();

}

Content Page:

Protected void page_load (Object sender, eventargs E)
{
Master. evt1 + = new masterpage. noargeventhandler (F1 );
}

Public void F1 ()
{}
(
Thu)Call functions on the master page on the Content Page

The content page can directly callPublic
Function.

Nesting of the master page:

The master page can be nested, so that a master page references another page as its parent page. You can use nested master pages to create componentized master pages. For example, a large site may contain a master page that defines the appearance of the site. Then, the content partners of different sites can define their respective child master pages. These child master pages reference the site master pages and define the appearance of the content of the partner accordingly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.