I have a parent master page (Master.Master) and child master page (Child.Master). The Child.Master inherits Master.Master master page file. Now in the Child.Master i want to set the visibility of Div (whose ID is Div1) to false, for which i’m using the following code:
protected void Page_Load(object sender, EventArgs e)
{
this.FindControl("Div1").Visible = false;
}
Here is the code in the Child Master Page file:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Webstore.Master.cs" Inherits="WebStore.WebStoreMaster" MasterPageFile="~/Login.Master" %>
<asp:Content ID="UserMaster" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<div id="Div1" runat="server">
<div id="Sidebar" runat="server" style="float: left; margin-top: 100px; margin-right: 20px;">
</div>
</div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</asp:Content>
The compiler is giving me the following error:
Object reference not set to an instance of an object.
Can someone explain why is it happening so ??
Thanks in anticipation
EDIT:
In this case, if the div is a top level element, and you are in the page_load of the child master page in which the div resides, you should just be able to do
Why not use a Panel control?