Hi John,
Take a look at this:
Code:
Partial Class AboutUs
Inherits System.Web.UI.Page
Public DisplayPanel As Boolean
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DisplayPanel = False
End Sub
End Class
What do you think this code does? Override the DisplayPanel of the Master Page? In that case; nope it doesn't. It simply creates *another* boolean inside the Content Page that in no way is associated with the one in the Master Page. If you want a property or field on a Master Page that you can control from a content page, you need to tell the content page the type of the Master Page so you can access its members. Try something like this:
1. Use the same Master Page as you have now with the public DisplayPanel field in it.
2. Create a content page based on this Master Page and add the following MasterType reference to it:
Code:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
Make sure you adjust the MasterPageFile and VirtualPath properties to point to your Master Page.
3. The Master property of your content page is now strongly typed to your specific Master Page, enabling you to do something like this in the Content Page:
Code:
Me.Master.DisplayPanel = False ' Or True
This should do the trick and hide or show the panel based on the value you pass to Me.Master.DisplayPanel.
A few other observations: Instead of a field, you can also use a property or even a ViewState property as explained in the bok. And you can collapse the If statement to this if you want:
Panel1.Visible = DisplayPanel
although you may find your expanded version easier to read.
Hope this helps,
Imar