Click here to Skip to main content
13,148,214 members (50,645 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I cannot access master form objects in my code:
//Mater form Script
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication2.Site1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <asp:ContentPlaceHolder ID="head" runat="server">
    <style type="text/css">
            width: 100%;
            width: 179px;
    <form id="form1" runat="server">
        <table class="style1">
                <td class="style2">
                    <asp:TreeView ID="TreeView1" runat="server" 
                            <asp:TreeNode Text="New" Value="New">
                            <asp:TreeNode Text="Edi" Value="Edi">
                            <asp:TreeNode Text="Delete" Value="Delete">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
//Content form Script
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %>
<%@ MasterType VirtualPath="~/Site1.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

public partial class WebForm2 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            Master.treevew1  //  Here I cannot access masterform objects

Please help
Posted 13-Feb-13 22:11pm
Updated 14-Feb-13 3:57am
ryanb31 14-Feb-13 10:00am
It's hard to tell exactly what your problem is, but I think you are saying that you can't access MasterPage objects from the Page that is using the master? If so, try adding <%@ MasterType VirtualPath="~/Master.Master" %> to your aspx page.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Master.treevew1  //  Here I cannot access masterform objects

You cannot directly access controls of master page.

You need to either strongly couple the master page with child page in page tag OR you need to use FindControl to find the control in master page OR you can expose a public property in Master page that exposes the needed server control.

Pick the one you like.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170924.2 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100