Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Locate Conditional Formatting and Custom Validation in InfoPath 2010
Conditionally Display Different Values In a Single Expression Box
Create a Button With a Blank Label
Create Shared Rules
Perform a Case-Insensitive String Comparison without Using Translate()
5 MOST POPULAR
Access a Method in a Master Page with Code-Behind
Pass Query String Parameters to an ASP.NET Xml Control
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Configure IIS 7 for Custom Error Pages
5 MOST FORGOTTEN
Create a Rusted Text Effect Using Styles
Convert Between Time and Decimal
Install Windows 7 Beta onto a Virtual Machine
Create a Drop Cap Using CSS
Enable Themes in Windows Server
Books
Murach's ASP.NET 2.0 Web Programming with VB 2005
ASP.NET 2.0 Website Programming Problem - Design - Solution
Microsoft Visual C# .NET Step by Step
Mastering Web Development with Microsoft Visual Studio 2005
Microsoft ADO.NET Step by Step
Magazines
Inside Web Design
.net: The Internet Magazine
.net
Asp.net Professional
Soa Web Services Journal
DVDs
Beginner's .NET XML Web Services 2004
Visually Learn Visual Basic .NET in 12 Hours
Beginner's ASP.NET in VB.NET 2003
Programming Visual Basic .NET and ADO.NET with SQL Server and Access
Beginner's ASP.NET in C# 2003
Microsoft MVP
Very PopularMost Viewed
This article has been viewed 12530 times.

Access a Method in a Master Page with Code-Behind

Page 3 of 3
Written by Gregory Scot Collins
Friday, 16 June 2006, 7:09 AM

Create the Child.master file

Copy the contents of Listing 5 into a text editor, and then save the file as Child.master. Be sure to save it in the same folder as the Parent.master file.

Create the Child.master.cs file

Copy the contents of Listing 6 into a text editor, and then save the file as Child.master.cs. Be sure to save it in the same folder as the Parent.master file.

Create the Default.aspx file

Copy the contents of Listing 7 into a text editor, and then save the file as Default.aspx. Be sure to save it in the same folder as the Parent.master file.

Create the Default.aspx.cs file

Copy the contents of Listing 8 into a text editor, and then save the file as Default.aspx.cs. Be sure to save it in the same folder as the Parent.master file.

Try it

Copy or upload all six files to the same folder on your Web server, and then navigate to the Default.aspx page. In this example, we navigate to http://localhost/Default.aspx and receive the following response:
Load Page
* Processing ChildMasterFromPage()
* Processing ParentMasterFromPage()
Load Child.Master
* Processing ParentMasterFromChildMaster()
Load Parent.Master
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
List of Figures
Listing 1 - Code for accessing a method in an immediate master page.
Listing 2 - Code for accessing a method in a parent master page.
Listing 3 - The Parent.master file.
Listing 4 - The Parent.master.cs file.
Listing 5 - The Child.master file.
Listing 6 - The Child.master.cs file.
Listing 7 - The Default.aspx file.
Listing 8 - The Default.aspx.cs file.
See Also
Access a Method in a Master Page without Code-Behind
Access a Method in Global.asax without Code-Behind
Access a Method in Global.asax with Code-Behind
Article Tags
Great Deals
TigerDirect Exclusive Deals, Limited Time Offers, Act Now And Save!
Find all current special offers on Adobe products.
Try SugarSync Free!
Join WebHost4Life.com
TigerDirect
Computers4SURE (4SURE.com - An Office Depot Co.)
Copyright © 2006-2010 Braintrove. All rights reserved. Braintrove, braintrove.com, and the Braintrove logo are trademarks of Gregory Scot Collins in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Any rights not expressly granted herein are reserved.