473,597 Members | 2,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I access a Master Page Public Property from a Base Page

I am trying to access a Public property on a Master Page from a Base Page.

On the content pages I have the MasterType Directive set up as follows:
<%@ MasterType virtualpath="~/Master.master" %>

On the Master Page I have a public property exposed:
Public Property ErrorMessage() As String
Get
Return txtError.InnerT ext
End Get
Set(ByVal value As String)
txtError.InnerT ext = value
rowError.Visibl e = True
End Set
End Property
From the Content Page I can access the property:
Me.Master.Error Message = "Some Error Message."

If I try and access the Master Page Property from an inherited Base Page with:
Me.Master.Error Message = "Some Error Message."
the IDE highlights the error with:
ErrorMessage is not a member of System.Web.UI.M asterPage

Is there some way I can cast the Base Page Master property to the strongly
typed Master Page and access the ErrorMessage property?

Nov 9 '07 #1
6 9137
On Nov 9, 12:03 pm, Jay Pondy <jpo...@Augusta Newsprint.comwr ote:
I am trying to access a Public property on a Master Page from a Base Page.

On the content pages I have the MasterType Directive set up as follows:
<%@ MasterType virtualpath="~/Master.master" %>

On the Master Page I have a public property exposed:
Public Property ErrorMessage() As String
Get
Return txtError.InnerT ext
End Get
Set(ByVal value As String)
txtError.InnerT ext = value
rowError.Visibl e = True
End Set
End Property

From the Content Page I can access the property:
Me.Master.Error Message = "Some Error Message."

If I try and access the Master Page Property from an inherited Base Page with:
Me.Master.Error Message = "Some Error Message."
the IDE highlights the error with:
ErrorMessage is not a member of System.Web.UI.M asterPage

Is there some way I can cast the Base Page Master property to the strongly
typed Master Page and access the ErrorMessage property?
Dim myMaster As New {masterClassNam e}
myMaster.ErrorM essage = "Some Error Message."

Nov 9 '07 #2
Almost there but...

I created a BaseMaster class that inherits from System.Web.UI.M asterPage And
placed my Public Property there:
Public Class BaseMaster : Inherits System.Web.UI.M asterPage

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Load
'Make the error table row invisible
CType(Page.Mast er.FindControl( "rowError") , HtmlTableRow).V isible = False
End Sub
Public Property ErrorMessage() As String
Get
Return CType(Page.Mast er.FindControl( "txtError") ,
HtmlGenericCont rol).InnerText
End Get
Set(ByVal value As String)
Trace.Write("Ba seMaster.ErrorM essage.Set")
CType(Page.Mast er.FindControl( "txtError") ,
HtmlGenericCont rol).InnerText = value
CType(Page.Mast er.FindControl( "rowError") , HtmlTableRow).V isible =
True
End Set
End Property
End Class
In my Master Page I now inherit from BaseMaster and I CAN now access the
Property from my content pages:
CType(Page.Mast er, BaseMaster).Err orMessage = "Some Error Message."

BUT...

All of my Pages inherit from a BasePage class that contains a Page_Error handler
from where I would like to access the MasterPage property when an error occurs:

Public Class BasePage : Inherits System.Web.UI.P age

Private Sub Page_Error(ByVa l sender As Object, ByVal e As System.EventArg s)
Handles MyBase.Error
CType(Page.Mast er, BaseMaster).Err orMessage =
Server.GetLastE rror.Message
End Sub

End Class
The problem now is that when I generate an error on the content page the Page
Error handler in my BasePage class fires and it sets the public property in my
BaseMaster but nothing is displayed on the page (the URL is correct for the
content page) the only HTML rendered is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

There is no Master and no Content HTML. I'm missing a call to something
somewhere.

On Fri, 9 Nov 2007 03:03:01 -0800, Jay Pondy <jp****@Augusta Newsprint.com>
wrote:
>I am trying to access a Public property on a Master Page from a Base Page.

On the content pages I have the MasterType Directive set up as follows:
<%@ MasterType virtualpath="~/Master.master" %>

On the Master Page I have a public property exposed:
Public Property ErrorMessage() As String
Get
Return txtError.InnerT ext
End Get
Set(ByVal value As String)
txtError.InnerT ext = value
rowError.Visibl e = True
End Set
End Property
From the Content Page I can access the property:
Me.Master.Error Message = "Some Error Message."

If I try and access the Master Page Property from an inherited Base Page with:
Me.Master.Error Message = "Some Error Message."
the IDE highlights the error with:
ErrorMessage is not a member of System.Web.UI.M asterPage

Is there some way I can cast the Base Page Master property to the strongly
typed Master Page and access the ErrorMessage property?
Nov 9 '07 #3
Unclear. The last part would make me think you try to access in a base class
to a property you defined in a derived class. This is the other way round
(i.e. what a base class is allowed to do is automatically doable by its
derived classes).

--
Patrice

"Alexey Smirnov" <al************ @gmail.coma écrit dans le message de news:
11************* *********@z24g2 00...legr oups.com...
On Nov 9, 12:03 pm, Jay Pondy <jpo...@Augusta Newsprint.comwr ote:
>I am trying to access a Public property on a Master Page from a Base
Page.

On the content pages I have the MasterType Directive set up as follows:
<%@ MasterType virtualpath="~/Master.master" %>

On the Master Page I have a public property exposed:
Public Property ErrorMessage() As String
Get
Return txtError.InnerT ext
End Get
Set(ByVal value As String)
txtError.InnerT ext = value
rowError.Visibl e = True
End Set
End Property

From the Content Page I can access the property:
Me.Master.Error Message = "Some Error Message."

If I try and access the Master Page Property from an inherited Base Page
with:
Me.Master.Error Message = "Some Error Message."
the IDE highlights the error with:
ErrorMessage is not a member of System.Web.UI.M asterPage

Is there some way I can cast the Base Page Master property to the
strongly
typed Master Page and access the ErrorMessage property?

Dim myMaster As New {masterClassNam e}
myMaster.ErrorM essage = "Some Error Message."

Nov 9 '07 #4
even better than a cast, tell asp.net to do it.

<%@ MasterType TypeName="MyMas ter" %>

-- bruce (sqlwork.com)
Jay Pondy wrote:
I am trying to access a Public property on a Master Page from a Base Page.

On the content pages I have the MasterType Directive set up as follows:
<%@ MasterType virtualpath="~/Master.master" %>

On the Master Page I have a public property exposed:
Public Property ErrorMessage() As String
Get
Return txtError.InnerT ext
End Get
Set(ByVal value As String)
txtError.InnerT ext = value
rowError.Visibl e = True
End Set
End Property
From the Content Page I can access the property:
Me.Master.Error Message = "Some Error Message."

If I try and access the Master Page Property from an inherited Base Page with:
Me.Master.Error Message = "Some Error Message."
the IDE highlights the error with:
ErrorMessage is not a member of System.Web.UI.M asterPage

Is there some way I can cast the Base Page Master property to the strongly
typed Master Page and access the ErrorMessage property?
Nov 9 '07 #5
Hi Jay,

As for accessing propertes in Master page, you can also consider the
following means:

#define a public interface which contains the properties or method you need
#let master implement the interface and in content page, simply cast Master
page to that interface and call those interface methods. e.g.

=========Interf ace============ =======
public interface IError
{
string ErrorInfo {get;set; }
}

=========Master page=========== ===
public partial class Masters_err : System.Web.UI.M asterPage, IError
{
............... .......
=============== =======

thus, you do not need to define base classes. For the problem that the
page doesn't display any UI after "Page_Error " event, I think this is
because when there occurs unhandled exception, the original page processing
sequence is broken, therefore, you can not expect it to render the page
content as normal (if there occurs unhandled exception). The "Page_Error "
or "Application_Er ror" event just provide you a point to capture this error
status and the recommended approach to show error info is defining a custom
error page or manually do redirection in "Page_Error " event (to your own
error page). You can store the last error info in SessionState if necessary.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>From: Jay Pondy <jp****@bellsou th.net>
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
Subject: Re: How can I access a Master Page Public Property from a Base
Page
>Date: Fri, 09 Nov 2007 07:18:50 -0500
>
Almost there but...

I created a BaseMaster class that inherits from System.Web.UI.M asterPage
And
>placed my Public Property there:
Public Class BaseMaster : Inherits System.Web.UI.M asterPage

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s)
>Handles Me.Load
'Make the error table row invisible
CType(Page.Mast er.FindControl( "rowError") , HtmlTableRow).V isible =
False
End Sub
Public Property ErrorMessage() As String
Get
Return CType(Page.Mast er.FindControl( "txtError") ,
HtmlGenericCon trol).InnerText
End Get
Set(ByVal value As String)
Trace.Write("Ba seMaster.ErrorM essage.Set")
CType(Page.Mast er.FindControl( "txtError") ,
HtmlGenericCon trol).InnerText = value
CType(Page.Mast er.FindControl( "rowError") ,
HtmlTableRow).V isible =
>True
End Set
End Property
End Class
In my Master Page I now inherit from BaseMaster and I CAN now access the
Property from my content pages:
CType(Page.Mast er, BaseMaster).Err orMessage = "Some Error Message."

BUT...

All of my Pages inherit from a BasePage class that contains a Page_Error
handler
>from where I would like to access the MasterPage property when an error
occurs:
>
Public Class BasePage : Inherits System.Web.UI.P age

Private Sub Page_Error(ByVa l sender As Object, ByVal e As
System.EventArg s)
>Handles MyBase.Error
CType(Page.Mast er, BaseMaster).Err orMessage =
Server.GetLast Error.Message
End Sub

End Class
The problem now is that when I generate an error on the content page the
Page
>Error handler in my BasePage class fires and it sets the public property
in my
>BaseMaster but nothing is displayed on the page (the URL is correct for the
content page) the only HTML rendered is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252"></HEAD>
><BODY></BODY></HTML>

There is no Master and no Content HTML. I'm missing a call to something
somewhere.

On Fri, 9 Nov 2007 03:03:01 -0800, Jay Pondy <jp****@Augusta Newsprint.com>
wrote:
>>I am trying to access a Public property on a Master Page from a Base Page.

On the content pages I have the MasterType Directive set up as follows:
<%@ MasterType virtualpath="~/Master.master" %>

On the Master Page I have a public property exposed:
Public Property ErrorMessage() As String
Get
Return txtError.InnerT ext
End Get
Set(ByVal value As String)
txtError.InnerT ext = value
rowError.Visibl e = True
End Set
End Property
From the Content Page I can access the property:
Me.Master.Error Message = "Some Error Message."

If I try and access the Master Page Property from an inherited Base Page
with:
> Me.Master.Error Message = "Some Error Message."
the IDE highlights the error with:
ErrorMessage is not a member of System.Web.UI.M asterPage

Is there some way I can cast the Base Page Master property to the
strongly
>>typed Master Page and access the ErrorMessage property?
Nov 12 '07 #6
Thanks Steven.
"Steven Cheng[MSFT]" wrote:
Hi Jay,

As for accessing propertes in Master page, you can also consider the
following means:

#define a public interface which contains the properties or method you need
#let master implement the interface and in content page, simply cast Master
page to that interface and call those interface methods. e.g.

=========Interf ace============ =======
public interface IError
{
string ErrorInfo {get;set; }
}

=========Master page=========== ===
public partial class Masters_err : System.Web.UI.M asterPage, IError
{
............... .......
=============== =======

thus, you do not need to define base classes. For the problem that the
page doesn't display any UI after "Page_Error " event, I think this is
because when there occurs unhandled exception, the original page processing
sequence is broken, therefore, you can not expect it to render the page
content as normal (if there occurs unhandled exception). The "Page_Error "
or "Application_Er ror" event just provide you a point to capture this error
status and the recommended approach to show error info is defining a custom
error page or manually do redirection in "Page_Error " event (to your own
error page). You can store the last error info in SessionState if necessary.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
From: Jay Pondy <jp****@bellsou th.net>
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
Subject: Re: How can I access a Master Page Public Property from a Base
Page
Date: Fri, 09 Nov 2007 07:18:50 -0500

Almost there but...

I created a BaseMaster class that inherits from System.Web.UI.M asterPage
And
placed my Public Property there:
Public Class BaseMaster : Inherits System.Web.UI.M asterPage

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s)
Handles Me.Load
'Make the error table row invisible
CType(Page.Mast er.FindControl( "rowError") , HtmlTableRow).V isible =
False
End Sub
Public Property ErrorMessage() As String
Get
Return CType(Page.Mast er.FindControl( "txtError") ,
HtmlGenericCont rol).InnerText
End Get
Set(ByVal value As String)
Trace.Write("Ba seMaster.ErrorM essage.Set")
CType(Page.Mast er.FindControl( "txtError") ,
HtmlGenericCont rol).InnerText = value
CType(Page.Mast er.FindControl( "rowError") ,
HtmlTableRow).V isible =
True
End Set
End Property
End Class
In my Master Page I now inherit from BaseMaster and I CAN now access the
Property from my content pages:
CType(Page.Mast er, BaseMaster).Err orMessage = "Some Error Message."

BUT...

All of my Pages inherit from a BasePage class that contains a Page_Error
handler
from where I would like to access the MasterPage property when an error
occurs:

Public Class BasePage : Inherits System.Web.UI.P age

Private Sub Page_Error(ByVa l sender As Object, ByVal e As
System.EventArg s)
Handles MyBase.Error
CType(Page.Mast er, BaseMaster).Err orMessage =
Server.GetLastE rror.Message
End Sub

End Class
The problem now is that when I generate an error on the content page the
Page
Error handler in my BasePage class fires and it sets the public property
in my
BaseMaster but nothing is displayed on the page (the URL is correct for the
content page) the only HTML rendered is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

There is no Master and no Content HTML. I'm missing a call to something
somewhere.

On Fri, 9 Nov 2007 03:03:01 -0800, Jay Pondy <jp****@Augusta Newsprint.com>
wrote:
>I am trying to access a Public property on a Master Page from a Base Page.

On the content pages I have the MasterType Directive set up as follows:
<%@ MasterType virtualpath="~/Master.master" %>

On the Master Page I have a public property exposed:
Public Property ErrorMessage() As String
Get
Return txtError.InnerT ext
End Get
Set(ByVal value As String)
txtError.InnerT ext = value
rowError.Visibl e = True
End Set
End Property
From the Content Page I can access the property:
Me.Master.Error Message = "Some Error Message."

If I try and access the Master Page Property from an inherited Base Page
with:
Me.Master.Error Message = "Some Error Message."
the IDE highlights the error with:
ErrorMessage is not a member of System.Web.UI.M asterPage

Is there some way I can cast the Base Page Master property to the
strongly
>typed Master Page and access the ErrorMessage property?

Nov 14 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6925
by: WFB | last post by:
Hi, I have a base class from which all of my pages derive (ABCBasePage). For example, ABCCustomerSelect Inherits ABCPasePage. I would now like to have ABCPocketSelect which should inherit from ABCCustomerSelect. My problem is that when ABCPocketSelect is loaded the Page_Load event in ABCBasePage is called, followed by the load event for ABCCustomerSelect - and I would like to skip the ABCCustomerSelect load event.. My basic code is...
4
2797
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than one runat=server form on a asp.net page. However, I still want developers to be able to use asp.net controls to create some apps that are created on the page. So I need multiple forms on a asp.net page(doesn't everyone). I purchased the...
10
6025
by: Davíð Þórisson | last post by:
Please can someone tell me how on earth to create an instance of my top level (base) Page class so that I can access it's objects from an user control?? Someone told me public myParent = (default_aspx) this.Page; where default_aspx is the class name of the base Page...
3
1778
by: Jeff User | last post by:
Hello I am using C#, .net1.1 Vis Studio 2003 I am using homeBase.aspx.cs page as a base for several other aspx/aspx.cs web pages. The base page handles some operations that are common to all pages. like this: somepage... public class homeBase : System.Web.UI.Page .... then other pages.....
1
3813
by: xs | last post by:
Hi, Is it possible to access Master Pages from Ascx directly? In an Aspx, by entering the following , <%@ MasterType VirtualPath="~/Pages/Master.Master"%> , I can easily access its property using this.Master. But can I do that using Ascx controls? What can I do to access it directly? Thanks
3
6406
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property BarLabelText. I now have a contentpage "FooBar.aspx", where "Bar.master" is the master page and in the content section has the control "Foo.ascx".
3
1921
by: Pini | last post by:
Hi all,In asp.net 1.x i creates a basepage that extends System.Web.UI.Page class. I created this file in a web appplcaition project and then refernced it from another projects. All the pages in this project inherited from this new BasePage ionstead of the Page class. In asp.net 2.0 i dont seem to make this work. I did the same thing. precompile the project and then added refernce to the assemblies in the precompiled directory.
3
2357
by: William Youngman | last post by:
I am on a team that is developing a proposal generation web application and we are using a custom base page (ProGenBase.cs) located in the app_code directory and all of the app's web pages inherit from this custom page. Additionally I have a main menu tab control that is located in a master page and certain tabs are displayed dependant on the users authentication level. I am using boolean properties in the master page to control the visible...
4
3096
by: DotNetNewbie | last post by:
Hi, I have a .aspx page that has a master page. In the master page, I have a Literal Control, and I created a public property that allows you to set the liBlah.Text of the literal control. The idea was that the .aspx page could simple use the property to set the value of the literal, but for some reason the property is not
0
7981
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8284
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.