asp.net page template *inheritance)

J

John Boers

I am trying to create a template for my website. But I have a problem, the
system says BC30469: Reference to a non-shared member requires an object
reference and points to the statement PageBase.Render( writer ).

I create the template by overriding the System.Web.UI.Page.Render method.
Then in every page I refer to the designed template. Please explain to me
where I go wrong.

Look here for the live errormessage:
http://johnboers.europe.webmatrixhosting.net/template.aspx

I use two files, see below.

Thank you for your time,

John

The files
Template.aspx
---
<% @Page Language="VB" AutoEventWireup="true" src="template.vb"
Inherits="PageBase" %>

<form id="pagecontent" method="post" runat="server">

<B> the content in HTML </B>
It should appear.

</form>
---

and template.vb
---
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls


Public Class PageBase
inherits System.Web.UI.Page
protected overrides sub Render(writer as HTMLTextWriter)

' First we will build up the html document,
' the head section and the body section.
writer.Write( "<html><head><title>John's test
pagina</title></head><body>example text" )

' Then we allow the base class to render the
' controls contained in the ASPX file.
PageBase.Render( writer )

' Finally we render the final tags to close
' the document.
Writer.Write( "</body></html>" )
end sub
end class
---
 
M

Marina

This doesn't compile, because Render is an instance method - you were
calling it by using the class name: 'PageBase'.

If this did even compile and run - you would get a stackoverflowexception -
because you would constantly be calling the same method - the one you are
in!.

You want to call MyBase.Render(writer) - 'MyBase' is the keyword to refer to
the base class in VB.
 
J

jobo

Thanks it works but..... I don't understand why.
I have to use the render method of mybase, but I never declare or import
MyBase so where is it defined?

Perhaps I need some more documentation of the object model, do you know a
good source or tutorial.

John
 

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

Top