how to use base page

I created two separate VS2003 projects - web app with asp.net in vb and a class library. My goal is to create one dll that will contain all common code and have this code used by the web app.

1. class library: MyBase

'contents of BasePage.vb
Imports System
Imports System.Web.UI 'Error - Namespace or type 'UI' for the Imports 'System.Web.UI' cannot be found.
Namespace BasePageVB
Public Class BasePage
Inherits Page 'Error - Type 'Page' is not defined.
End Class
End Namespace

1.1. Why the errors?

1.2. Once the errors are corrected, can I put the dll on the web server and use it in the web app?
     ex: wwwroot/bin/MyBase.dll



2. asp.net/vb: testbase
Add a reference: in the dialog box, click .Net and browse to find the MyBase.dll. What I'd like to do is inherit the base page as opposed to the System.Web.UI.Page:

'contents of default.vb
Imports System

Public Class WebForm1
    'Inherits System.Web.UI.Page
    Inherits [MyBase].BasePageVB

2.1 why do i get errors?


what is the best way of doing this?
fwstealAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Elvio Lujan.Net Senior DeveloperCommented:
use:

1.1 Make sure you have the System reference in the project... and then use: Inherits System.Web.UI.Page
1.2 Yes... just add the reference to the dll and you'll can use it
hismightinessCommented:
It certainly sounds like you are missing a reference to one or more classes of the .Net Framework.  Make sure you have a reference to the System and System.Web classes in your references section of your solution explorer.  Also, a good thing to do in the code above is to include the namespace of the class you are using.  This can tell you at which point your reference(s) have failed.

EXAMPLE:

Imports System
Imports System.Web.UI

Namespace BasePageVB
     Public Class BasePage
          Inherits System.Web.UI.Page
     End Class
End Namespace


Also, your page may not be in the same Namespace as your base class...
EXAMPLE:

Imports System

Namespace BasePageVB
     Public Class WebForm1
          Inherits BasePageVB.BasePage
     End Class
End Namespace

OR:

Imports System

Public Class WebForm1
     Inherits BasePageVB.BasePage
End Class
fwstealAuthor Commented:
class library - I added a reference to system.web and it cleaned up all the errors; then recompiled the code.

In the web app I get:
Imports System

Public Class WebForm1
    'Inherits System.Web.UI.Page
    Inherits [MyBase].BasePageVB

error: type expected.

the dll is added as a reference
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

hismightinessCommented:
Are you getting a compile error for the inherits line?  I would suspect that you should.  Your inherits statement is attempting to inherit a class, not a type (as expected).  Try this:

Public Class WebForm1
    'Inherits System.Web.UI.Page
    Inherits BasePageVB.BasePage
fwstealAuthor Commented:
Here is my error by doing that: Type 'BasePageVB.BasePage' is not defined.
hismightinessCommented:
Wrap your class in the same namespace as the base page.  It is in a different namespace, so it cannot see it.

FROM THE PREVIOUS EXAMPLE:

Namespace BasePageVB
     Public Class WebForm1
          Inherits BasePageVB.BasePage
     End Class
End Namespace
irps20001Commented:
did u try this?
Imports BasePageVB.BasePage ( or give ur dll namespace name here)
Public Class WebForm1
    'Inherits System.Web.UI.Page
    Inherits BasePageVB.BasePage

Rana

fwstealAuthor Commented:
I tried both and get the following errors


Imports System
Namespace BasePageVB
    Public Class WebForm1
        Inherits [MyBase].BasePageVB     'error - type expected.
        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


Imports System
Imports [MyBase].BasePageVB
Public Class WebForm1
    Inherits [MyBase].BasePageVB    'error - type expected.
    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


hismightinessCommented:
You are still trying to inherit the CLASS and not the TYPE:

Inherits [MyBase].BasePageVB     'error - type expected.

SHOULD BE:

Inherits BasePageVB.BasePage
fwstealAuthor Commented:
Inherits BasePageVB.BasePage

gives me the following error:

type BasePageVB.BasePage is not defined


----------

Imports System
Namespace BasePageVB
  Public Class WebForm1
     Inherits BasePageVB.BasePage 'Type 'BasePageVB.BasePage' is not defined.
       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
hismightinessCommented:
Well, from the snippets you have posted, that looks like it should work.  Do you have the namespace defined in your project settings?  Also, what happens as you type the inherits line?  Does it not lead you to the class/type via intellisense?
fwstealAuthor Commented:
yes:

Property Page dialog box
Common Properties
Imports - Namespace: BasePageVB is present int he Project imports section

hismightinessCommented:
What about the intellisense?  Did that not lead you to the correct path to the type?  You can determine that using the Class View window.
fwstealAuthor Commented:
if i allow intellisense to work by default it writes it as:

Inherits [MyBase].BasePageVB
fwstealAuthor Commented:
this works:

Inherits [MyBase].BasePageVB.BasePage

now i need to put something in the base class file; like a string value and present it on the default.aspx file to know whether it works or not
hismightinessCommented:
I am not sure about the [MyBase] part, but if intellisense finds it, then it is right 98% of the time.  However, you are indeed referencing the Type now, not the Class by using BasePage.  I do something very similar to my applications.  It works nicely.
fwstealAuthor Commented:
MyBase/BasePage.vb - class file
---------
Imports System
Imports System.Web.UI

Namespace BasePageVB
    Public Class BasePage
        Inherits System.Web.UI.Page

        Public name As String
        Private doorid As Integer

        Public Sub New()
            doorid = 0
            name = "nothing"
        End Sub

        Public Property intID() As Integer
            Get
                intID = doorid
            End Get
            Set(ByVal Value As Integer)
                doorid = Value
            End Set
        End Property

        Public Overrides Sub Dispose()
            name = ""
            doorid = 0
        End Sub

        Protected Overrides Sub Finalize()
        End Sub
    End Class



    Module Module1
        Sub Main()
            Dim dDoor As New BasePage
            dDoor.name = "Red Apple Door"
            dDoor.intID = 1
            dDoor.Dispose()
        End Sub
    End Module
End Namespace


****************************************************
testbase/WebForm1.aspx.vb - asp.net
have a project reference to class file

Imports System
Namespace BasePageVB
    Public Class WebForm1
        'Inherits System.Web.UI.Page
        Inherits [MyBase].BasePageVB.BasePage
#Region " Web Form Designer Generated Code "
        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        End Sub
        Protected WithEvents lblProductName As System.Web.UI.WebControls.Label
        '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
            lblProductName.Text = name.ToString
        End Sub
    End Class
End Namespace
******************************************************


Error:
Namespace or type 'BasePageVB' in the project-level Imports 'BasePageVB' cannot be found.
hismightinessCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.