Update the page properties in master page : Master page « User Control and Master Page « ASP.Net






Update the page properties in master page



<%@ Page Language="C#" MasterPageFile="~/Default.master" 
                       AutoEventWireup="true" 
                       CodeFile="Default.aspx.cs" 
                       Inherits="ProgrammedHome" 
                       Title = "Programmed Master Page Home" %>
<%@ MasterType VirtualPath="~/Default.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="sideContent" Runat="Server">
  <h2>title</h2>
  <p>AAA</p>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" Runat="Server">
  <h1>title</h1>
  <p>BBB</p>
</asp:Content>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ProgrammedHome : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      Master.AdImageUrl = "~/Images/ads/ad3.gif";
      Master.AdNavigateUrl = "http://www.java2s.com";
   }
}

File: Default.master

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Default.master.cs" Inherits="ProgrammedContentMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
   <form id="form1" runat="server">
      <div id="container">
         <div id="header">
            <asp:Image runat="server" ID="imgLogo" ImageUrl="~/cool.gif" />
            <div id="bannerAd">
            <asp:HyperLink ID="imgbtnAd" runat="server" />
            </div>
         </div>
         <div id="sideArea">
            <div id="menu">
               <asp:BulletedList ID="blstSample" runat="server" DisplayMode="HyperLink">
                  <asp:ListItem Value="">Home</asp:ListItem>
                  <asp:ListItem Value="">Products</asp:ListItem> 
                  <asp:ListItem Value="">About</asp:ListItem>
               </asp:BulletedList>
            </div>
            <div id="sideAreaBox">
               <asp:ContentPlaceHolder ID="sideContent" runat="server">
                 <p>default side content</p>
               </asp:ContentPlaceHolder>  
            </div>          
         </div>
         <div id="mainArea">
            <asp:ContentPlaceHolder ID="mainContent" runat="server">
              <p>default main content</p>
            </asp:ContentPlaceHolder>
         </div>
         <div id="footer">
            <p>this is a test.</p>
         </div>         
      </div>
   </form>
</body>
</html>

File: Default.master.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ProgrammedContentMaster : System.Web.UI.MasterPage
{
   public string AdImageUrl
   {
      get { return imgbtnAd.ImageUrl; }
      set { imgbtnAd.ImageUrl = value; }
   }

   public string AdNavigateUrl
   {
      get { return imgbtnAd.NavigateUrl; }
      set { imgbtnAd.NavigateUrl = value; }
   }
}

 








Related examples in the same category

1.Nested master page (C#)
2.Use master page (C#)
3.Master page with trace (C#)
4.Two Master Pages (C#)
5.Link content page with master page
6.Master page with Default Content
7.Master in page derivative
8.Two pieces of contentplaceholder
9.master for print
10.Control title in master page with content page code
11.Nested master page
12.Use image to fill the filler in master page
13.Code behind and master page
14.Specifying master page in Web.config causes every content page to inherit from the master page
15.Specifying the master page for a specific folder in the Web.config file: Use
16.A master page that creates a GUID on the first request (C#)
17.A master page that creates a GUID on the first request (VB)
18.A master page that exposes a custom property (C#)
19.A master page that exposes a custom property (VB)
20.Exposing a server control from a master page as a public property (C#)
21.Exposing a server control from a master page as a public property (VB)
22.Overriding some default content in the content page (C#)
23.Overriding some default content in the content page (VB)
24.Using Page_PreInit to assign the master page programmatically (C#)
25.Using Page_PreInit to assign the master page programmatically (VB)
26.A content page that can work with more than one master page
27.Nested master
28.Put site navigation in the master page
29.Master pages exposing an object model for content pages to programmatically modify elements on the master.