Hi All,
This is my master page code
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SiteMaster.master.cs"
Inherits="ChildPage_Call_Js_in_MasterPage.SiteMaster" %>
<!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">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="phMenu" runat="server"></asp:PlaceHolder>
<asp:ContentPlaceHolder ID="ContentPlaceHolderBody" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
<script type="text/javascript" language="javascript">
function showHideMasterPageContent() {
debugger;
var phMenu = document.getElementById("<%=phMenu.ClientID%>");
// phMenu.style.display = 'none';
}
</script>
</body>
</html>
And this is my Childpage code :
<%@ Page Title="" Language="C#" MasterPageFile="~/SiteMaster.master" AutoEventWireup="true"
CodeBehind="ChildPage1.aspx.cs" Inherits="ChildPage_Call_Js_in_MasterPage.ChildPage1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderBody" runat="server">
<script type="text/javascript" language="javascript">
$(document).ready(function () {
debugger;
showHideMasterPageContent();
});
</script>
</asp:Content>
Now what I want to do is, using JavaScript, hide the "phMenu" contents in the childpage. For this, I have written a function called " showHideMasterPageContent " in the masterpage which I am calling in the child page.
My trouble is that, I get a null reference since obviously, when I looked at the source, I see that only the contents of phMenu are rendered and not the phMenu control itself. Now how to refer to phMenu in JS ?