Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NETMasterpage
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 179px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="style1">
            <tr>
                <td class="style2">
                    <asp:TreeView ID="TreeView1" runat="server" 
                        onselectednodechanged="TreeView1_SelectedNodeChanged">
                        <nodes>
                            <asp:TreeNode Text="New" Value="New">
                            <asp:TreeNode Text="Edi" Value="Edi">
                            <asp:TreeNode Text="Delete" Value="Delete">
                        </nodes>
                    
                </td>
                <td>
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
 
//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
Edited 14-Feb-13 3:57am
v2
Comments
ryanb31 at 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
good
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 950
1 OriginalGriff 508
2 Abhinav S 233
3 thatraja 225
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,142
1 OriginalGriff 4,665
2 Peter Leow 3,774
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid