Solved

Problem exposing master page properties...

Posted on 2006-07-24
7
725 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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