Interview answers verified by specialists.

Find interview questions and answers on this website:

See right interview answers on 30 common job interview questions

How you can access the Properties and Controls of Master Pages from content pages?

You can access the Properties and Controls of Master Pages from content pages. In many situations you need User's Name in different content pages. You can set this value inside the master page and then make it available to content pages as a property of the master page.

We will follow the following steps to reference the properties of master page from content pages.

Step: 1

Create a property in the master page code-behind file.

public String UserName
get {
return (String)Session["Name"];
set {
Session ["Name"] = value;

Step: 2

Add the @ MasterTypedeclaration to the .aspx content page to reference master properties in a content page. This declaration is added just below the @ Page declaration as follows:

<%@ Page Title=" TEST" Language="C#" MasterPageFile="~/CareerRide.master" AutoEventWireup="true" CodeFile="CareerRideWelcome.aspx.cs" Inherits="CareerRideWelcome" %>

<%@ MasterTypeVirtualPath="~/CareerRide.master" %>

Step: 3

Once you add the @ MasterType declaration, you can reference properties in the master page using the Master class. For example take a label control that id is ID="Label1"

Label1.Text= Master.UserName ;

For referencing controls in the Master Page we will write the following code.

Content Page Code.

protected void Button1_Click(object sender, EventArgs e)
TextBox txtName= (TextBox)Master.FindControl("TextBox1");

To reference controls in a master page, callMaster.FindControlfrom the content page.

Do you know that?

Clients search Elance for online hires over 6.1M times each year. That's 696 times per hour Next


Getting payments for Freelancers
1. Read how to register and get earned money

2. Open account within 5 minPayoneer sing up to get free $25