Solved

Problem exposing master page properties...

Posted on 2006-07-24
7
719 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
Comment Utility
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
Comment Utility
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
Comment Utility
...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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 37

Author Comment

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

Expert Comment

by:raterus
Comment Utility
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
Comment Utility
...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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now