R
Rotsey
Hi,
I have created class that subclass the Page class.
The problem is that it calls my OnInit methd ok and creates the HTML
but the Page_load of my webpage that inherits the base class never gets
called.
I have put a breakpoint on the OnInit for subclass and at the Page_Load.
The breakpoint in the Page_Load never accessed.
Here is the code
rotsey
Imports System
Imports System.Web.UI
Namespace BasePagesVB
Public Class BasePage
Inherits Page
#Region "Properties"
Private baseTItleArea As TableCell
Protected ReadOnly Property TitleBar() As TableCell
Get
Return baseTItleArea
End Get
End Property
Private baseNavArea As TableCell
Protected ReadOnly Property NavigationBar() As TableCell
Get
Return baseNavArea
End Get
End Property
Private baseContentArea As TableCell
Protected ReadOnly Property ContentArea() As TableCell
Get
Return baseContentArea
End Get
End Property
Private baseForm As HtmlForm
Protected ReadOnly Property Form() As HtmlForm
Get
Return baseForm
End Get
End Property
Private baseTitle As HtmlGenericControl
Protected Property Title() As String
Get
Return baseTitle.InnerText
End Get
Set(ByVal Value As String)
baseTitle.InnerText = value
End Set
End Property
#End Region
#Region "BuildFrame()"
Private Sub BuildFrame()
' Create our opening tags
Dim baseHtml As New LiteralControl("<html>")
baseHtml.ID = "baseHtml"
Me.Controls.Add(baseHtml)
Dim baseHead As New LiteralControl("<head>")
baseHead.ID = "baseHead"
Me.Controls.Add(baseHead)
' Page Title
baseTitle = New HtmlGenericControl("title")
baseTitle.ID = "baseTitle"
Me.Controls.Add(baseTitle)
' Page Title
'Dim baseCSS = New LiteralControl("<LINK href='Styles.css' type='text/css'
rel='stylesheet'>")
'Me.Controls.Add(baseCSS)
Dim baseHead2 As New LiteralControl("<LINK href=" & Chr(34) &
Page.ResolveUrl("~/Styles.css") & Chr(34) & " type='text/css'
rel='stylesheet'></head>")
'Dim baseHead2 As New LiteralControl("<LINK href='Styles.css'
type='text/css' rel='stylesheet'></LINK></head>")
'Dim baseHead2 As New LiteralControl("</head>")
baseHead2.ID = "baseHead2"
Me.Controls.Add(baseHead2)
Dim baseBody As New LiteralControl("<body>")
baseBody.ID = "baseBody"
Me.Controls.Add(baseBody)
' Add the form
baseForm = New HtmlForm
baseForm.ID = "baseForm"
Me.Controls.Add(baseForm)
' Set up our table
Dim tbl As New Table
'tbl.GridLines = GridLines.Both
tbl.CellPadding = 0
tbl.CellSpacing = 0
'tbl.BorderColor = Color.Black
'tbl.BorderStyle = BorderStyle.Solid
'tbl.BorderWidth = Unit.Point(1)
tbl.Width = Unit.Percentage(100)
' Title Bar Row
Dim rw As New TableRow
baseTItleArea = New TableCell
baseTItleArea.ColumnSpan = 3
rw.Height = Unit.Pixel(40)
rw.Cells.Add(baseTItleArea)
tbl.Rows.Add(rw)
' Navigation and Content
rw = New TableRow
baseNavArea = New TableCell
baseNavArea.Attributes("Style") = "width: 20px"
rw.Cells.Add(baseNavArea)
baseContentArea = New TableCell
'baseContentArea.Attributes("Style") = "width: 1000px"
baseContentArea.CssClass = "MainCell"
baseContentArea.HorizontalAlign = HorizontalAlign.Left
rw.Cells.Add(baseContentArea)
Dim baseExtraArea As New TableCell
rw.Cells.Add(baseExtraArea)
tbl.Rows.Add(rw)
Dim baseCopyright As TableCell
Dim objAnchor As New HtmlAnchor
objAnchor.HRef = Me.ResolveUrl("~/Admin/frmAdminHome.aspx")
objAnchor.InnerText = "Admin"
objAnchor.Attributes("Style") = "color: DarkGray;"
rw = New TableRow
baseCopyright = New TableCell
baseCopyright.ColumnSpan = 1
rw.Height = Unit.Pixel(40)
rw.Cells.Add(baseCopyright)
baseCopyright = New TableCell
baseCopyright.ColumnSpan = 1
rw.Height = Unit.Pixel(40)
rw.Cells.Add(baseCopyright)
baseCopyright.ForeColor = Color.DarkGray
baseCopyright.Controls.Add(New LiteralControl("<br><br><hr>"))
baseCopyright.Controls.Add(objAnchor)
baseCopyright.Controls.Add(New LiteralControl(" | (c) Copyright Lester
Associates 2006"))
baseCopyright = New TableCell
baseCopyright.ColumnSpan = 1
rw.Cells.Add(baseCopyright)
tbl.Rows.Add(rw)
baseForm.Controls.Add(tbl)
'Close our tags
'Dim str As String
'str = "<script type='text/javascript'>"
'str += " //<![CDATA[ "
'str += " document.write('scr' + 'ipt
src='http://crazyegg.com/pages/scripts/33338.js?'+(new Date()).getTime()+'"
'str += " type='text/javascript'></'+'/script>');"
'str += "//]]> </script>"
Dim baseBody2 As New LiteralControl("</body>")
baseBody2.ID = "baseBody2"
Me.Controls.Add(baseBody2)
Dim baseHtml2 As New LiteralControl("</html>")
baseHtml2.ID = "baseHtml2"
Me.Controls.Add(baseHtml2)
End Sub
#End Region
#Region "OnInit & MoveControls"
Private Sub MoveControls()
Dim ph As Integer = 0
While Me.Controls.Count > ph
If IsNothing(Me.Controls(ph).ID) OrElse Me.Controls(ph).ID.Length < 4 _
OrElse (Me.Controls(ph).ID.Length > 3 And _
Me.Controls(ph).ID.Substring(0, 4).ToLower() <> "base") Then
baseContentArea.Controls.Add(Me.Controls(ph))
Else
ph += 1
End If
End While
End Sub
Private Sub AddHeader()
TitleBar.Controls.Add(Page.LoadControl(Page.ResolveUrl("~/AppMenu.ascx")))
'TitleBar.Controls.Add(Page.LoadControl("AppMenu.ascx"))
End Sub
Protected Overrides Sub OnInit(ByVal e As EventArgs)
BuildFrame()
MoveControls()
AddHeader()
MyBase.OnInit(e)
End Sub
#End Region
End Class
End Namespace
I have created class that subclass the Page class.
The problem is that it calls my OnInit methd ok and creates the HTML
but the Page_load of my webpage that inherits the base class never gets
called.
I have put a breakpoint on the OnInit for subclass and at the Page_Load.
The breakpoint in the Page_Load never accessed.
Here is the code
rotsey
Imports System
Imports System.Web.UI
Namespace BasePagesVB
Public Class BasePage
Inherits Page
#Region "Properties"
Private baseTItleArea As TableCell
Protected ReadOnly Property TitleBar() As TableCell
Get
Return baseTItleArea
End Get
End Property
Private baseNavArea As TableCell
Protected ReadOnly Property NavigationBar() As TableCell
Get
Return baseNavArea
End Get
End Property
Private baseContentArea As TableCell
Protected ReadOnly Property ContentArea() As TableCell
Get
Return baseContentArea
End Get
End Property
Private baseForm As HtmlForm
Protected ReadOnly Property Form() As HtmlForm
Get
Return baseForm
End Get
End Property
Private baseTitle As HtmlGenericControl
Protected Property Title() As String
Get
Return baseTitle.InnerText
End Get
Set(ByVal Value As String)
baseTitle.InnerText = value
End Set
End Property
#End Region
#Region "BuildFrame()"
Private Sub BuildFrame()
' Create our opening tags
Dim baseHtml As New LiteralControl("<html>")
baseHtml.ID = "baseHtml"
Me.Controls.Add(baseHtml)
Dim baseHead As New LiteralControl("<head>")
baseHead.ID = "baseHead"
Me.Controls.Add(baseHead)
' Page Title
baseTitle = New HtmlGenericControl("title")
baseTitle.ID = "baseTitle"
Me.Controls.Add(baseTitle)
' Page Title
'Dim baseCSS = New LiteralControl("<LINK href='Styles.css' type='text/css'
rel='stylesheet'>")
'Me.Controls.Add(baseCSS)
Dim baseHead2 As New LiteralControl("<LINK href=" & Chr(34) &
Page.ResolveUrl("~/Styles.css") & Chr(34) & " type='text/css'
rel='stylesheet'></head>")
'Dim baseHead2 As New LiteralControl("<LINK href='Styles.css'
type='text/css' rel='stylesheet'></LINK></head>")
'Dim baseHead2 As New LiteralControl("</head>")
baseHead2.ID = "baseHead2"
Me.Controls.Add(baseHead2)
Dim baseBody As New LiteralControl("<body>")
baseBody.ID = "baseBody"
Me.Controls.Add(baseBody)
' Add the form
baseForm = New HtmlForm
baseForm.ID = "baseForm"
Me.Controls.Add(baseForm)
' Set up our table
Dim tbl As New Table
'tbl.GridLines = GridLines.Both
tbl.CellPadding = 0
tbl.CellSpacing = 0
'tbl.BorderColor = Color.Black
'tbl.BorderStyle = BorderStyle.Solid
'tbl.BorderWidth = Unit.Point(1)
tbl.Width = Unit.Percentage(100)
' Title Bar Row
Dim rw As New TableRow
baseTItleArea = New TableCell
baseTItleArea.ColumnSpan = 3
rw.Height = Unit.Pixel(40)
rw.Cells.Add(baseTItleArea)
tbl.Rows.Add(rw)
' Navigation and Content
rw = New TableRow
baseNavArea = New TableCell
baseNavArea.Attributes("Style") = "width: 20px"
rw.Cells.Add(baseNavArea)
baseContentArea = New TableCell
'baseContentArea.Attributes("Style") = "width: 1000px"
baseContentArea.CssClass = "MainCell"
baseContentArea.HorizontalAlign = HorizontalAlign.Left
rw.Cells.Add(baseContentArea)
Dim baseExtraArea As New TableCell
rw.Cells.Add(baseExtraArea)
tbl.Rows.Add(rw)
Dim baseCopyright As TableCell
Dim objAnchor As New HtmlAnchor
objAnchor.HRef = Me.ResolveUrl("~/Admin/frmAdminHome.aspx")
objAnchor.InnerText = "Admin"
objAnchor.Attributes("Style") = "color: DarkGray;"
rw = New TableRow
baseCopyright = New TableCell
baseCopyright.ColumnSpan = 1
rw.Height = Unit.Pixel(40)
rw.Cells.Add(baseCopyright)
baseCopyright = New TableCell
baseCopyright.ColumnSpan = 1
rw.Height = Unit.Pixel(40)
rw.Cells.Add(baseCopyright)
baseCopyright.ForeColor = Color.DarkGray
baseCopyright.Controls.Add(New LiteralControl("<br><br><hr>"))
baseCopyright.Controls.Add(objAnchor)
baseCopyright.Controls.Add(New LiteralControl(" | (c) Copyright Lester
Associates 2006"))
baseCopyright = New TableCell
baseCopyright.ColumnSpan = 1
rw.Cells.Add(baseCopyright)
tbl.Rows.Add(rw)
baseForm.Controls.Add(tbl)
'Close our tags
'Dim str As String
'str = "<script type='text/javascript'>"
'str += " //<![CDATA[ "
'str += " document.write('scr' + 'ipt
src='http://crazyegg.com/pages/scripts/33338.js?'+(new Date()).getTime()+'"
'str += " type='text/javascript'></'+'/script>');"
'str += "//]]> </script>"
Dim baseBody2 As New LiteralControl("</body>")
baseBody2.ID = "baseBody2"
Me.Controls.Add(baseBody2)
Dim baseHtml2 As New LiteralControl("</html>")
baseHtml2.ID = "baseHtml2"
Me.Controls.Add(baseHtml2)
End Sub
#End Region
#Region "OnInit & MoveControls"
Private Sub MoveControls()
Dim ph As Integer = 0
While Me.Controls.Count > ph
If IsNothing(Me.Controls(ph).ID) OrElse Me.Controls(ph).ID.Length < 4 _
OrElse (Me.Controls(ph).ID.Length > 3 And _
Me.Controls(ph).ID.Substring(0, 4).ToLower() <> "base") Then
baseContentArea.Controls.Add(Me.Controls(ph))
Else
ph += 1
End If
End While
End Sub
Private Sub AddHeader()
TitleBar.Controls.Add(Page.LoadControl(Page.ResolveUrl("~/AppMenu.ascx")))
'TitleBar.Controls.Add(Page.LoadControl("AppMenu.ascx"))
End Sub
Protected Overrides Sub OnInit(ByVal e As EventArgs)
BuildFrame()
MoveControls()
AddHeader()
MyBase.OnInit(e)
End Sub
#End Region
End Class
End Namespace