I am having master page.Below is the Designer part.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<asp:Label ID="lblMaster" runat="server" Text=""></asp:Label>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
In page_load of Master Page ,I write lblMaster.Text = "Master";
In my Asp.Net page,
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MasterPractice.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="lblfrm" runat="server" Text="Label"></asp:Label>
</asp:Content>
In my page_load I get,
lblfrm.Text = "Form";
I am getting the mentioned error at my master page.
Please guide me for mentioned concerns.
Because the
Label
is inside aContentPlaceHolder
control, you must first get a reference to theContentPlaceHolder
and then use itsFindControl
method to locate theLabel
.How to: Reference ASP.NET Master Page Content
Edit: To find
lblMaster
as requested in comment: