Solved

Problem exposing master page properties...

Posted on 2006-07-24
7
728 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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