Connecting Tech Pros Worldwide Forums | Help | Site Map

Inheritance Problem (src vs. Codebehind)

Michael
Guest
 
Posts: n/a
#1: Nov 18 '05
Hello,

I'm trying to implement sample I found on page templates, so I do not have
to maintain "<html><head>..." on all my documents. But don't let that
confuse you, this is an inheritance problem.

Basically, I'm using VS.NET IDE for development, If I use the src="..." tag
in the @Page directive it works, but if I use codebehind="...", I get a
runtime error that it cannot find my first class I'm inheriting. It's
almost like the assembly dll it is compiling doesn't contain the namespace
I've defined (But I have rebuilt it, even checked the timestamp to make sure
it is being updated)

The error I get from the browser when requesting default.aspx is as follows:
Parser Error Message: Could not load type 'aspdotnet.PageTemplateSetup'.
(and it highlights my @page directive line)

I originally had a C# example and changed it down to VB.NET, so I'm sure I'm
missing something simple.

Here is my source files, if it helps.

default.aspx
*****************
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb"
Inherits="aspdotnet.PageTemplateSetup" %>

<form id="testform" runat="server">
<h3>Testing Templates</h3>
</form>

default.aspx.vb
*******************
Imports System

Namespace aspdotnet

Public Class PageTemplateSetup
Inherits aspdotnet.PageTemplateBase

Sub PageTemplateSetup()
PageTitle = "My Page Title"
End Sub
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

End Class

End Namespace

PageTemplateBase.vb
**********************
Imports System

Namespace aspdotnet

Public Class PageTemplateBase
Inherits aspdotnet.PageBase

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
'First we will build up the html document, the head section
'and the body section.
writer.Write("<html><head><title>" & PageTitle &
"</title></head><body>")

'The base class will render the controls from the
'derived .ASPX file.
MyBase.Render(writer)

writer.Write("</body></html>")
End Sub


End Class
End Namespace

PageBase.vb
******************
Imports System

Namespace aspdotnet

Public Class PageBase
Inherits System.Web.UI.Page

Private _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

**********

Thank you for any help you can give!
--Michael



Michael
Guest
 
Posts: n/a
#2: Nov 18 '05

re: Inheritance Problem (src vs. Codebehind)


I figured out my problem, in the default.aspx.vb file I had to take the
class I use there out of the aspdotnet namespace. Now why that worked I do
not know...

"Michael" <raterus@localhost> wrote in message
news:elqTDGZyDHA.3416@tk2msftngp13.phx.gbl...[color=blue]
> Hello,
>
> I'm trying to implement sample I found on page templates, so I do not have
> to maintain "<html><head>..." on all my documents. But don't let that
> confuse you, this is an inheritance problem.
>
> Basically, I'm using VS.NET IDE for development, If I use the src="..."[/color]
tag[color=blue]
> in the @Page directive it works, but if I use codebehind="...", I get a
> runtime error that it cannot find my first class I'm inheriting. It's
> almost like the assembly dll it is compiling doesn't contain the namespace
> I've defined (But I have rebuilt it, even checked the timestamp to make[/color]
sure[color=blue]
> it is being updated)
>
> The error I get from the browser when requesting default.aspx is as[/color]
follows:[color=blue]
> Parser Error Message: Could not load type 'aspdotnet.PageTemplateSetup'.
> (and it highlights my @page directive line)
>
> I originally had a C# example and changed it down to VB.NET, so I'm sure[/color]
I'm[color=blue]
> missing something simple.
>
> Here is my source files, if it helps.
>
> default.aspx
> *****************
> <%@ Page Language="vb" AutoEventWireup="false"[/color]
Codebehind="default.aspx.vb"[color=blue]
> Inherits="aspdotnet.PageTemplateSetup" %>
>
> <form id="testform" runat="server">
> <h3>Testing Templates</h3>
> </form>
>
> default.aspx.vb
> *******************
> Imports System
>
> Namespace aspdotnet
>
> Public Class PageTemplateSetup
> Inherits aspdotnet.PageTemplateBase
>
> Sub PageTemplateSetup()
> PageTitle = "My Page Title"
> End Sub
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
>
> 'NOTE: The following placeholder declaration is required by the[/color]
Web[color=blue]
> Form Designer.
> 'Do not delete or move it.
> Private designerPlaceholderDeclaration As System.Object
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form[/color]
Designer[color=blue]
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
> #End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
>
> End Class
>
> End Namespace
>
> PageTemplateBase.vb
> **********************
> Imports System
>
> Namespace aspdotnet
>
> Public Class PageTemplateBase
> Inherits aspdotnet.PageBase
>
> Protected Overrides Sub Render(ByVal writer As
> System.Web.UI.HtmlTextWriter)
> 'First we will build up the html document, the head section
> 'and the body section.
> writer.Write("<html><head><title>" & PageTitle &
> "</title></head><body>")
>
> 'The base class will render the controls from the
> 'derived .ASPX file.
> MyBase.Render(writer)
>
> writer.Write("</body></html>")
> End Sub
>
>
> End Class
> End Namespace
>
> PageBase.vb
> ******************
> Imports System
>
> Namespace aspdotnet
>
> Public Class PageBase
> Inherits System.Web.UI.Page
>
> Private _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
>
> **********
>
> Thank you for any help you can give!
> --Michael
>
>[/color]


Closed Thread