Problem after changing Inherits System.Web.UI.Page to Inherit BasePage (that includes Inherit System.Web.UI.Page)

ullenulle
ullenulle used Ask the Experts™
on
Hi there.

I'm a step further in my VB.NET study... and I ran into a problem when I'm supposed to create a BasePage.vb where I add the "Inherit System.Web.UI.Page" and after that edit an existing code behind from "Inherit System.Web.UI.Page" to "Inherit BasePage".
When I test the page, I get an error, that:

.... is not allowed here because it does not extend class 'System.Web.UI.Page'.

Even though it's all a bit new to me, it doesn't make sense, because the BasePage does inherit the System.Web.UI.Page...
Any idea what I'm doing wrong?
Let me know if you need more info.

Best regards

Ulrich
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi Ulrich,

Couple of questions
1. What you are trying to do?
2. Please share the code that is giving you this error.
3. Which version of Visual Studio you are using?

Regards,
Chinmay.

Author

Commented:
Hi.

Thank you for your response. Here's some answers to your questions:

1) and 2): I have this simple beginning of a project with a login.aspx page looking like this:
<%@ Page Title="Login to DAMMED" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPages/Frontend.Master" CodeBehind="Login.aspx.vb" Inherits="dammed.Login" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="server">
</asp:Content>

Open in new window


The code behind looks like this:
Partial Class Login
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
End Class

Open in new window


Then I created a BasePage like this:
Public Class BasePage
    Inherits System.Web.UI.Page

    Private Sub Page_PreRender(
        ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

        If Me.Title = "Untitled Page" Or String.IsNullOrEmpty(Me.Title) Then
            Throw New Exception(
                "Page title cannot be ""Untitled Page"" or an empty string.")
        End If
    End Sub
End Class

Open in new window


That BasePage is supposed to be inherited in the login.asps.vb, so it will look like this:
Partial Class Login
    Inherits BasePage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
End Class

Open in new window

Right afterdoing this, there's a red curl under "Load" indicating an error.
If I ignore and test the page, I first get a warning that there were errors building the project. I contunied anyways, and I get this error:

Login.aspx.vb(4,93): error BC30590: Event 'Load' cannot be found.

3) I use Visual Studio 2019 (version 16.1.6)

Best regards

Ulrich
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Ulrich,

Must be something else. I could run everything fine (Even though VS was showing many errors).

Finally I changed file names and voila...  Sample this

PageRoot.vb
Public Class PageRoot
    Inherits System.Web.UI.Page

    Private Sub Page_PreRender(
        ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

        If Me.Title = "Untitled Page" Or String.IsNullOrEmpty(Me.Title) Then
            Console.WriteLine("Page title cannot be ""Untitled Page"" or an empty string.")
        End If
    End Sub
End Class

Open in new window


TestForm.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestForm.aspx.vb" Inherits="CrmXpress.VB.WebFormApp.TestForm" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>TEST</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Ha Ha Ha...
        </div>
    </form>
</body>
</html>

Open in new window


TestForm.aspx.vb
Public Class TestForm
    Inherits PageRoot

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
End Class

Open in new window


Regards,
Chinmay.

Author

Commented:
Hi Chinmay.

Hmm... I guess I just need to start over again. I must've written a name wrong somewhere. Thank you for your response. :-)

Best regards

Ulrich
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi Ulrich,

Glad I could help. I just changed the name of the files. I suspect they were conflicting with some system reserved keywords. You don't really need to start over.

Regards,
Chinmay.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial