Reputation: 4747
I'm trying to access a master page property from content page so that I can set a literal on master page file easily. So I created the master page property this way in Masterpage vb file
Public Property PropertyOnMasterPage() As String
Get
' Get value of control on master page
Return ltr_companyname.Text
End Get
Set(ByVal value As String)
' Set new value for control on master page
ltr_companyname.Text = value
End Set
End Property
But I've no idea how can I get or set this property from content page.(based on this tutorial). Thats in C#. But when I tried Master. intellisense not showing that master page property. So how can I get the master page property on contetn page. Do it required to refer anything on the content page?
EDIT
These are master page and content page screenshot.. In the content page screenshot, you can see intellisense not finding that property
Content Page
Master page
Upvotes: 1
Views: 1899
Reputation: 32704
The thing you're missing is that you need to set the MasterType
from the content page so that it will know what class the master page is. Then it will be strongly typed and there will be no need to cast it.
Put this below your @ Page
directive, obviously with the correct path to your master page.
<%@ MasterType VirtualPath="~/masters/SourcePage.master" %>
Upvotes: 3
Reputation: 50728
I have not had luck with strong typing reference to the master page, so what I normally do is create an interface:
Public Interface IMyMaster
Property PropertyOnMasterPage As String
End Interface
On your master page file, implement it:
Public Class SiteMaster
Inherits MasterPage
Implements IMyMaster
Public Property PropertyOnMasterPage As String Implements IMyMaster.PropertyOnMasterPage
End Class
And then convert the Me.Master reference to the interface, and access the property like:
CTYpe(Me.Master, IMyMaster).PropertyOnMasterPage
The interface adds a looser coupling (sort of) anyway.
Upvotes: 0
Reputation: 2327
In C# You can Use this.Master to Access the page Master page I think You should have Me.Master
so In content page you would end up like this
Me.Master.PropertyOnMasterPage
Upvotes: 1