How to access the property of master page

  • Thread starter Thread starter RedHair
  • Start date Start date
R

RedHair

I have a base page class A which inherits System.Web.UI.Page class
then a aspx page B inherits class A and have a master page C.
There is a property D (a string variable) in the master page C.

How can I access the property D from the base page class A?

PS: I know how to use reflection to access control of master page C from the
base class A.
 
You must obtain a refrence to your MasterPage.
Here is some Visual Basic code:

dim myMaster As YourMasterPageType = CType( Me.Master,
YourMasterPageType )
myMaster.YourProperty = "lalalalal"
 
First of all, when working with MasterPages its more useful to refer to a
"Content Page" rather than "base page class A."
Secondly, we strongly type the Master by including the following in a
content page...

<%@ MasterType VirtualPath="~/Masters/Whatever.master" %>

We can then access controls in the MasterPage using one of two techniques:

* Early Bound: properties
* Late Bound: FindControl method

I really haven't tried to reuse a variable declared in the MasterPage from a
Content Page.

<%= Clinton Gallagher
 
The reason I want to work with master page from the base page class A is
because
sometimes the master page will be a little bit different depends on the
asp.net page.
I need to pass the parameters from base page class to master page since all
aspx
pages inherit the base page class, I don't need to call the subroutine in
each page.
 
Oops my bad, I have missunderstood your question.

I thought you want to access variables from the content page.
 
Back
Top