Response.Write In Class?



Consider the following class named "Constructor.vb" which exists in

Imports System
Imports System.Data
Imports System.Web
Imports System.Web.HttpResponse
Imports System.Web.UI.Page

Namespace cons
Public Class Constructor : Inherits Page
Public Sub Hello()
End Sub
End Class
End Namespace

When I try to compile the above class (in a folder named "Business"
which is a sub-folder in the "ASPX" folder) using

vbc /t:library /out:Business/Cons.dll /r:System.dll /r:System.Data.dll
/r:System.Web.dll Constructor.vb

I get the following 2 errors:


Type 'Page' is not defined.

pointing to the following line

Public Class Constructor : Inherits Page


Reference to a non-shared member requires an object reference.

pointing to the following line:


What am I doing wrong?

Secondly, to use a class in an ASPX page, is it always necessary to
compile it into a DLL & then import it as a namespace in the ASPX page?




Your first issue:
Error 1: In your Imports System.Web.UI.Page change it to: Imports

Error 2: Resolving the first error should most likely resolve this error.

Your second issue:
ASP.NET can automatically compile this class for you on demand, however, to
achieve this you must deploy the .vb file on the web server. Some people
don't like this so they pre-compile it like you did. If you don't have
issues deploying your .vb file, then in your aspx page you can define a Src
attribute setting the filename of the .vb file as your parameter.

<%@ Page language="VB" Src="Constructor.vb" %>

This should work, hopefully I didn't leave anyting out.

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