Solved

Problem exposing master page properties...

Posted on 2006-07-24
7
727 Views
Last Modified: 2012-06-27
my brain doesn't seem to be awake yet...(I'm hoping it'll wake up around wednesday or so)....but
I'm using vs2005, web application project, this is a project migrated from 1.1 up to 2.0...and I can't seem to access properties of the master page from a content page....

on the master page:
    Dim m_intCategory As Integer = 1
    Public Property TheCategoryID() As Integer
        Get
            Return m_intCategory
        End Get
        Set(ByVal value As Integer)
            m_intCategory = value
        End Set
    End Property



on the aspx of a content page:
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="defaultMaster.Master" CodeBehind="testNewMaster.aspx.vb" Inherits="Webvantage.testNewMaster"
    title="" %>
    <%@ MasterType VirtualPath="defaultMaster.Master" %>


in the codebehind, no intellisense for the property and so this fails:
 
Page.Master.TheCategoryID = 2

I know it is because somehow the content page is not referencing the master page at all....but I thought the directives:

<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="defaultMaster.Master" CodeBehind="testNewMaster.aspx.vb" Inherits="Webvantage.testNewMaster"
    title="" %>
    <%@ MasterType VirtualPath="defaultMaster.Master" %>

That those 2 lines are what wires up and references the correct master page?
Only it doesn't seem to be doing it.

Err is of course:
'TheCategoryID' is not a member of 'System.web.UI.MasterPage'.


I've tried setting the master from the cbh file first like:
        Page.MasterPageFile = "defaultMaster.Master"
        Page.Master.TheCategoryID = 2

...still not finding it

I don't really want to use FindControl to get to stuff on the master page...what am I missing?

Thanks!!!!

Sam
0
Comment
Question by:samtran0331
7 Comments
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 17167366
This "problem" has to do with the new code-compilation model of asp.net 2.0, where your masterpage isn't compiled until the application is started up.  Only way I've found to get by this is to have your MasterPage inherit from a base class in your app_code folder.  Then you put your properties for the masterpage in the base class.  
0
 
LVL 7

Expert Comment

by:osiris247
ID: 17167461
i never put Page.Master....only Master  so...

Master.TheCategoryID =

then i get the intellisence......

Mind you this is in C#, not sure if that makes a difference??

Steve
0
 
LVL 37

Author Comment

by:samtran0331
ID: 17167503
...thanks Michael...I had found a few posts saying the same thing off of Rick Strahl's blog...it wasn't the exact same issue...but his technique was something I thought might work...

...so I shouldn't have any problems if I create a base class for the master page that inherits ...UI.MasterPage
as well as making my content pages use a base class that inherits ...UI.Page
?

would you recommend I move the stuff in the base class for the content pages into the base class of the master?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Author Comment

by:samtran0331
ID: 17167533
Steve, are you using the default "web site project" or the "web application project" template?
0
 
LVL 33

Expert Comment

by:raterus
ID: 17167793
naa I wouldn't recommend copying page methods to the masterpage, I try to keep the base page of my masterpages as simple as possible and just have properties there related only to the layout of the page, not what the page is doing.
0
 
LVL 37

Author Comment

by:samtran0331
ID: 17183598
...see i told you my brain would wake up by Wednesday!

using a base class for the master worked like a charm....thanks for the tidbit on when the master gets compiled!
0
 

Expert Comment

by:Edward Joell
ID: 20834037
raterus, based on you answer are you saying that the application will not properly complete a build due to this issue unless yiou create a base class for the Master Page to inherit?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question