I created a very simple website for testing. Only one main page and one content page.
My content page is as follows:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="TestDiv1">bla bla</div>
<div id="TestDiv2">ble ble</div>
</asp:Content>
Now, based on some condition, I would like to show / hide this div. Therefore, I am trying to get to one of these divs using the Controls collection, for example:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ContentPlaceHolder myContent = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");
myContent.FindControl("TestDiv1").Visible = false;
}
}
}
}
But the above example does not work. None of the two div controls exist in the collection myContent.Controls. If I put, for example, a TextBox on my content page, I can contact it through the controls.
So what should I do to have access to the div control?
Wodzu