Accessing Properties in masterpage from content file

R

Rick

I am trying to access the properties defined int a masterpage from within a content page. the properties are not showing up when I try to access them from the content page.

Anyone have any suggestions?

MasterPage:
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="BasePageMaster.master.vb" Inherits="Digecenter.BasePageMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>

MasterPage Code:
Public Partial Class BasePageMaster

Public Property PageTitle() As String

Get

Return _pageTitle

End Get

Set(ByVal Value As String)

_pageTitle = Value

End Set

End Property

End Class


Content page Html:
<%@ Register TagPrefix="iswebgrid" Namespace="ISNet.WebUI.WebGrid" Assembly="ISNet.WebUI.WebGrid" %>
<%@ Page CodeBehind="codebehind.aspx.vb" inherits="codebehindfilenamehere" Language="vb" AutoEventWireup="false" enableViewStateMac="false" MasterPageFile="~/DigecenterBasePage.Master" %>
<%@ MasterType VirtualPath="~/MasterPages/BasePageMaster.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat=server>
--content here
</Content>

Content Page Code Behind:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

NOT SEEING THE PROPERTIES IN THE intelesense

Dim s as string = Me.Masterpage.property

End Sub

Thanks in Advance!
 
G

Guest

Rick,

If you look closely, it seems that you have a discrepency in your locations:
Content page Html:
<%@ Page ... MasterPageFile="~/DigecenterBasePage.Master" %>
<%@ MasterType VirtualPath="~/MasterPages/BasePageMaster.Master" %>

could that be what's confusing VS?
 
J

Jialiang Ge [MSFT]

Hello Rick,

I have tested you sample code on my side. The content page is able to
access the property of the master page after some small modifications of
your codes.
1. Attribute 'CodeBehind' in the @Page directive is no longer supported in
ASP.NET 2.0, so I changed the 'CodeBehind' to 'CodeFile' in both
BasePagemaster.master and codebehind.aspx.
2. In your Content page, you set the MasterPageFile in @Page directive as
'~/DigecenterBasePage.Master'. In the meantime, you set the VirtualPath of
@MasterType directive as '~/MasterPages/BasePageMaster.Master'. What is the
relationship between these two master pages? If they are simply inheriting
from System.Web.UI.MasterPage, you will get an exception: 'Unable to cast
object of type 'ASP.digecenterbasepage_master' to type
'ASP.masterpages_basepagemaster_master' in runtime. In my test, I change
the former to '~/MasterPages/BasePageMaster.Master'
3. In your content page html, you references a 3rd party control:
ISNet.WebUI.WebGrid. For convenience, I removed the line on my side.

After I made the changes above, I build the project and finally see that
the master property 'PageTitle' shows in the intelligence. Please have a
try and let me know whether it works on your side.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rick

I've made the following changes: When I change CodeBehind to Codefile I get
the following error:
'Context' is not a member of 'PageName.aspx'

<%@ Page Codefile="~/customer_clientswebgrid_edit.aspx.vb"
inherits="Digecenter.Customer_ClientsWebGrid_Edit" Language="vb"
AutoEventWireup="false" enableViewStateMac="false"
MasterPageFile="~/MasterPages/BasePageMaster.Master" %>

<%@ MasterType TypeName="DigeMaster"
VirtualPath="~/MasterPages/BasePageMaster.Master" %>
 
J

Jialiang Ge [MSFT]

Hello Rick

"Context" is a member of "System.Web.UI.Page". If you do not specify the
attributes 'CodeFile' and 'Inherits' in the @Page directive correctly, you
will receive the error: "Context is not a member of PageName.aspx". Please
check your CodeFile path and the 'Inherits' attribute, and let me know if
this suggestion could help you resolve the issue.

Besides, the MasterType directive must have exactly one attribute: TypeName
or VirtualPath. Please remove one from your MasterType directive.

Here is my test code for your references:

The structure of the test site:
Default.aspx
Default.aspx.vb
MasterPages\BasePageMaster.master
MasterPages\BasePageMaster.master.vb

In Default.aspx:
<%@ Page Language="VB" MasterPageFile="~/MasterPages/BasePageMaster.master"
EnableViewStateMac="false" AutoEventWireup="false"
CodeFile="~/Default.aspx.vb" Inherits="Digecenter._Default" title="Untitled
Page" %>
<%@ MasterType VirtualPath="~/MasterPages/BasePageMaster.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

In Default.aspx.vb:
Namespace Digecenter
Partial Class _Default
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Master.PageTitle = "hello world"
End Sub
End Class
End Namespace

In BasePageMaster.master:
<%@ Master Language="VB" AutoEventWireup="false"
CodeFile="BasePageMaster.master.vb" Inherits="Digecenter.BasePageMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

In BasePageMaster.master.vb
Namespace Digecenter
Partial Public Class BasePageMaster
Inherits System.Web.UI.MasterPage
Dim _pageTitle As String
Public Property PageTitle() As String
Get
Return _pageTitle
End Get
Set(ByVal value As String)
_pageTitle = value
End Set
End Property
End Class
End Namespace

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rick

Ok, something must be wrong with the setup, Because when I change the page
directive to Codefile and try to pick the url to the vb file. The dialog box
comes up and only shows the aspx files. If I select to show only code files
the only file that shows is the assembly.info.vb file. I can go directly to
the folder the web project is in, and see that all the .vb files are there.
 
J

Jialiang Ge [MSFT]

Hello Rick,

Because you said that your visual studio only showed the 'AssemblyInfo.vb'
file when you selected to list only code files, would you check to see
whether the vb files have been added into you project? To add the code
files into the project, you should right click your project in the Solution
Explorer, choose 'Add Existing Items' and select your vb files in your
project directory. Then please rebuild your project and let me know if it
works.

If it does not help, I suggest that you may re-create a new test site with
VS's new project wizard, then paste my sample codes in my last reply into
it and see whether your problem can be resolved.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rick

All of the vb files are included in the project. Still have same issue, I
tried your test and created a new project(ASPNET Web application) . I still
get the error in the html when using CodeFile:
'Context' is not a member of 'Filenamehere'
 
J

Jialiang Ge [MSFT]

Hello Rick,

Have you received my sample project? Would you let me know how does the
project work on your side? If you need further assistance, feel free to
let me know. I will be more than happy to be of assistance.

Have a great day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top