Inheritance Problem (src vs. Codebehind)

M

Michael

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
 
M

Michael

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...
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top