Saturday, September 26, 2015

Default content in contentplaceholder of a master page

Suggested Videos
Part 147 - Master pages in
Part 148 - Passing data from content page to master page
Part 149 - Passing data from master page to content page

A ContentPlaceHolder in a master page can include default content. 

Let's understand this with an example. The following ContentPlaceHolder in the master page has some default content in an <h1> tag.
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
    <h1>Content pages can override this content if they wish to</h1>

Now right click on the master page and select "Add Content Page". A new content page should be added and would see the following HTML on the content page
<%@ Page Title="" Language="C#" MasterPageFile="~/Site2.Master" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="WebFormsDemo.WebForm5" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

Notice that we have a content control in the content page. Normally we would place the controls and may be some text inside the content control. However, if we want the content page to default to the content in the ContentPlaceHolder of the master page.
1. Flip the content page to the design mode
2. Right click on the "ContentPlaceHolder" control and select "Default to Master's content"
3. You would get a confirmation dailog box
If you default to the Master Page content, everything in this region will be removed from the page. Do you want to continue?
4. Click Yes

Notice that the default content from the master page "ContentPlaceHolder" is displayed. Now, flip the content page to Source mode, and notice that, the content control is removed. So, if you want a content page to default to master page default content, all you need to do is to remove the content control from the content page.

If you are searching life partner. your searching end with now offer free matrimonial website which offer free message, free chat, free view contact information. so register here : Free matrimonial website