Solved

Problem exposing master page properties...

Posted on 2006-07-24
7
729 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

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!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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