Asp. NET Master Page

Source: Internet
Author: User
Tags access properties

An ASP. NET master page, which is primarily a page that sets up a consistent interface and is updated in a pinned page.

1-1 is shown

Page Header

Page (page content)

End of page

Figure 1-1 master Page

The General page is fixed page header and footer, only update page content, to achieve the page jump or content updates. In fact, the control iframe and a can also implement such a function.

For example:

<iframe name= "If" ></iframe>//updates or jumps to different pages within the IFRAME control.

<a target= "If" href= "ww.aspx" > Jump </a>//Click "Jump" to get the Ww.aspx page content and add it to the control named "if".

Note: Page jumps are implemented here. You'll need to add a lot of <a>, which will cause the code to repeat, and the effect interface is not good for the master page.

The master page and the Web forms that are nested in the master page correspond to the relationships. That is, note: "MasterPageFile". The equivalent, the child is big, mother obedient. You have, I change. Set the master page (mother) content to, table header, footer, table (id name is arbitrary). When a Web form (child) that is nested in a master page has a corresponding ContentPlaceHolderID value that is the ID value of the master page, the content that is displayed changes. For example, the following code shows the result: table header changed to footer (that is, the mother's value changed, listen to the child's words, change "table" to "change")

Master page:

<%@ Master language= "C #" autoeventwireup= "true" codebehind= "MyM.master.cs" inherits= "master page. MyM"%>

Web forms that are nested in a master page:

<%@ page title= "" Language= "C #" masterpagefile= "~/mym.master" autoeventwireup= "true" codebehind= "Ww.aspx.cs" inherits= "master page. WW"%>

Master Page

<asp:contentplaceholder id= "Head" runat= "Server" >

Table header

</asp:ContentPlaceHolder>

<asp:contentplaceholder id= "ContentPlaceHolder1" runat= "Server" >

In the table

</asp:ContentPlaceHolder>

<asp:contentplaceholder id= "ContentPlaceHolder2" runat= "Server" >

End of table

</asp:ContentPlaceHolder>

Or

Table header

<asp:contentplaceholder id= "ContentPlaceHolder1" runat= "Server" >

In the table

</asp:ContentPlaceHolder>

End of table

Web forms that are nested in master pages

<asp:content id= "Content2" contentplaceholderid= "ContentPlaceHolder1" runat= "Server" >

Change

</asp:Content>

Access controls and properties for master pages

to access controls on a master page by using the Master.findcontrol method

For example: form to get the content of a control on the master page, the following code.

Master page:

<asp:label id= "Label1" runat= "Server" text= " master page Label control contents " ></asp:Label>

Web forms that are nested in a master page:

<asp:content id= "Content2" contentplaceholderid= "ContentPlaceHolder1" runat= "Server" >

A web form nested in a master page gets the contents of a form control:

<asp:label id= "LA1" runat= "Server" ></asp:Label>

</asp:Content>

Label TT = (label) this. Master.findcontrol ("Label1");// Get master page Label control ID is Label1 of the content

This.la1.Text = TT. Text;

Reference @mastertypedirectives to access properties on the master page

You can change the properties of the master page on the form content page

Master page:

<asp:label id= "Label1" runat= "Server" text= " master page Label Control contents :" ></asp:label >

<%=this. mvalue%>//the background mvalue Assignment in the foreground interface

public string mvalue = "Original value";

public string Mvalue

{

get {return mvalue;}

set {Mvalue=value;}

}

Web forms that are nested in a master page:

<%@ MasterType virtualpath= "~/mym.master"%> (added on behalf of the dock, set the virtualpath value to the corresponding master page path.) )

Master.mvalue = "Hello!"; /Background Change the Mvalue value of the master page.

Asp. NET Master Page

Related Article

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.