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



Almost there but...

I created a BaseMaster class that inherits from System.Web.UI.MasterPage And
placed my Public Property there:


Public Class BaseMaster : Inherits System.Web.UI.MasterPage

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
'Make the error table row invisible
CType(Page.Master.FindControl("rowError"), HtmlTableRow).Visible = False
End Sub


Public Property ErrorMessage() As String
Get
Return CType(Page.Master.FindControl("txtError"),
HtmlGenericControl).InnerText
End Get
Set(ByVal value As String)
Trace.Write("BaseMaster.ErrorMessage.Set")
CType(Page.Master.FindControl("txtError"),
HtmlGenericControl).InnerText = value
CType(Page.Master.FindControl("rowError"), HtmlTableRow).Visible =
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.Master, BaseMaster).ErrorMessage = "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.Page

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
CType(Page.Master, BaseMaster).ErrorMessage =
Server.GetLastError.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 <jpondy@xxxxxxxxxxxxxxxxxxxx>
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.InnerText
End Get
Set(ByVal value As String)
txtError.InnerText = value
rowError.Visible = True
End Set
End Property


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

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

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



Relevant Pages

  • Re: Inheritence and overloading operators
    ... a class that inherits from this first class which has extra attributes ... overload to work correctly. ... Public Property Xas ... ... Public Overridable Function Equals(_ ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Generating live HTML server side controls from .Net classes
    ... I'm inheriting from a custom rolled master page class that is just that a class that inherits from web.ui.page but it has no designer associated with it. ... I want to generate some HTML inside the class and then that stuff will be on every actual .aspx page that inherits from my master page class. ... if I could get my master page class to generate some html inside it using proper server activatable html controls, then every page I use will inherit from my class masterPage and not web.ui.page and therefore it will have that nav bar on it. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Inheritence and overloading operators
    ... a class that inherits from this first class which has extra attributes ... overload to work correctly. ... Public Property Xas ... ... as Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Custom property on inherited form not showinf in property grid
    ... Form1 inherits System.Windows.Forms.Form ... Add a new public property - doesnt show in designer ... Form2 inherits Form1 ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: How can I access a Master Page Public Property from a Base Page
    ... As for accessing propertes in Master page, ... #define a public interface which contains the properties or method you need ... I created a BaseMaster class that inherits from System.Web.UI.MasterPage ... Public Property ErrorMessageAs String ...
    (microsoft.public.dotnet.framework.aspnet)