aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

How to access content page controls from master page

Jun 20, 2012

In this article I will explain how to access or get content or child page controls from master page in


In previous post I explained how to access master page controls from content page in Now I will explain how to access content page controls from master page in

To get child or content page control values in master page first write the following code in master page like this


<html xmlns="">
<head runat="server">
<title>Master Page with Controls</title>
<asp:ContentPlaceHolder id="head" runat="server">
<form id="form1" runat="server">
MasterPage Label:
<asp:Label ID="lblMaster" runat="server" />
MasterPage Textbox:
<asp:textbox ID="txtMaster" runat="server" />
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

After that write the code in Content Page Default.aspx will be like this

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/MasterPage.master" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<fieldset id="fld">
<legend><b>Content Page</b></legend>
Content Page Label Value:
<asp:Label ID="lblContent" Text="Sample Content Page label Control" runat="server"/>
<br />
Content Page Textbox Value:
<asp:Textbox ID="txtContent" Text="Sample Content Page Textbox Control" runat="server"/>
After that add following namespaces in MasterPage.master.cs page in codebehind

C# Code (MasterPage)

using System;
using System.Web.UI.WebControls;
Now add following code in code behind

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
Label cotentlbl = (Label)ContentPlaceHolder1.FindControl("lblContent");
TextBox contenttxt = (TextBox)ContentPlaceHolder1.FindControl("txtContent");
lblMaster.Text = cotentlbl.Text;
txtMaster.Text = contenttxt.Text;
VB.NET Code (MasterPage)

Imports System.Web.UI.WebControls
Partial Public Class MasterPage
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Dim cotentlbl As Label = DirectCast(ContentPlaceHolder1.FindControl("lblContent"), Label)
Dim contenttxt As TextBox = DirectCast(ContentPlaceHolder1.FindControl("txtContent"), TextBox)
lblMaster.Text = cotentlbl.Text
txtMaster.Text = contenttxt.Text
End If
End Sub
End Class

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Hafeez said...

This article (how to access child page controls from master page in helps for my project. Thanks

Unknown said...

how to access the child page grid view values from master page.......

Iti Tyagi said...

Will it be working when there are multiple content pages.

Unknown said...

how get controls from content page in master page , if we don't know the id of controls

Unknown said...

how to access controls from one content page to another content page?

Prabhat Kumar Mishra said...
This comment has been removed by the author.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.