Contacting base page to get MasterPage doesn't work....:(
Ok I have a blank project with a default page and a master page, and a Base page class in App_Data
Default.aspx has it's master page set, and inherits BasePage
If I add the following code into Default.aspx:
Code:
Dim obj As MasterPage = MyBase.Master
obj.AddMenuItem("Testing")
then this works.
If i add the above code into the basepage then it puts a squiggle under AddMenuItem as instead of declaring obj as my MasterPage (which is poorly named as MasterPage) it declares it as Web.UI.Msterpage.
Any ideas how I ref my masterpage from the basepage code? :(
woof
Re: Contacting base page to get MasterPage doesn't work....:(
Me.Master.FindControl("")....
Re: Contacting base page to get MasterPage doesn't work....:(
Ok...And how do you suppose I use that to get access to the AddItem function of my masterpage?????
:s
Re: Contacting base page to get MasterPage doesn't work....:(
If you call your masterpage WokasMasterPage, then due to VS 2005 crappy namespacing the following code does NOT work in a base page:
Code:
Dim myMaster As WokasMasterPage
The base page cannot see, hear or slap any kind of reference to the master page. As far as it's concerned, it doesn't exist. That is my problem.
So, your answer of using FindControl doesn't help as I cannot type cast it, and therefore cannot get access to the AddItem function.
Woka
Re: Contacting base page to get MasterPage doesn't work....:(
Quote:
Originally Posted by Wokawidget
The base page cannot see, hear or slap any kind of reference to the master page. As far as it's concerned, it doesn't exist. That is my problem.
That is not a problem. That's something 'by design'.
A MasterPage is a property of a normal Page, but each page may not necessarily have the same MasterPage value. Their types may be different. In that case, you probably want to check if the base page's MasterPage property is castable to type WokasMasterPage and then (cast) it to that type, then make a call to that method.
Re: Contacting base page to get MasterPage doesn't work....:(
Hmmmmm...
The base page cannot see, hear or slap any kind of reference to the master page.
How can I cast to an object that is not referenced.
I may as well type:
Code:
Dim obj As AnObjectThatDoesntExist
so, just to explain a little more. If I did the following in the base page:
Code:
Dim myMaster As MyMasterPage = CType(base.MasterPage, MyMasterPage)
Then 2 things will happen.
1, MyMasterPage is blue squiggly lined as the base page cannot see it.
2, it doesn't work.
Does that make sense now?
If I could get access to the MyMasterPage object/type/class/thing, whatever u wanna call it...then yes, I would have just type casted it. I know all pages etc return a standard MasterPage class and NOT a ref to the one actually being used.
I can write this code inside a web page, no problem....so:
Code:
Dim myMaster As MyMasterPage = CType(Me.MasterPage, MyMasterPage)
This works fine.
But it's when I create a simple BaseClass in my project. This gets put in the App_Data folder and the code in their cannot see my MyMasterPage for some reason :(
Woof
Re: Contacting base page to get MasterPage doesn't work....:(
I share your :(
Can you upload a sample project with the same setup? I want to try this.