Search code examples
asp.netinheritancewebformscode-behindvs-web-application-project

Web Form code behind not creating Partial Class, page inherits "ProjectName.ClassName" instead of just "ClassName". Visual Studio 2013


So I'm trying to make an "About" page that can be shared across many web applications that we use. To do this, I'm going to be saving the "AboutBox.aspx" and "AboutBox.aspx.vb" files on our web server. Then, from each application, I'll open a pop-up window that will call the AboutBox page by its url. The Problem I'm having is after I've created the page and copied it to the server, when I try to open the page it's giving me the error:

Parser Error Message: Could not load type 'DemoWebApp.AboutBox'.

Line 1:  <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="AboutBox.aspx.vb" Inherits="DemoWebapp.AboutBox" %>

So I'm assuming it's having an issue with "Inherits" having the project name "DemoWebApp" in front of the class name.

Also, the code behind file that was created with the web form has "Public Class AboutBox" instead of what I think they're supposed to have which is "Partial Class AboutBox"

I've tried just getting rid of "DemoWebApp." from the inherits and also just changing the code behind to being a partial class instead of public. This didn't work.

Additionally, someone else created a test web form page from an older version of Visual Studio. This web form didn't have the project title in the inherits and had a partial class instead of public. This page was copied to the server and worked just fine.

I'm using Visual Studio 2013, I'm not sure if it's an issue with this version or something else entirely.

Is there any way that, when you add a new web form file to the project, it will create the file the way I need it to?

EDIT:

Here is my AboutBox.aspx code:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="AboutBox.aspx.vb" Inherits="TestAboutBox.AboutBox" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body style="height:238px; width:486px; background-color:green">
    <form id="form1" runat="server">
            <div style="width:154px; height:232px; float:left;">
                <asp:Image ID="LogoImage" runat="server" Height="232px" ImageAlign="Middle" Width="154px" ImageUrl="small.png"/>
            </div>
            <div style="width:326px; height:232px; float:right">
                <asp:Label ID="LabelProductName" runat="server" Text="Product Name" Font-Size="8.25pt" Font-Names="Microsoft Sans Serif" style="margin:5px"></asp:Label>
                <br />
                <asp:Label ID="LabelVersion" runat="server" Text="Version" Font-Size="8.25pt" Font-Names="Microsoft Sans Serif" style="margin:5px"></asp:Label>
                <br />
                <asp:Label ID="LabelCopyright" runat="server" Text="Copyright" Font-Size="8.25pt" Font-Names="Microsoft Sans Serif" style="margin:5px"></asp:Label>
                <br />
                <asp:Label ID="LabelCompanyName" runat="server" Text="Company Name" Font-Size="8.25pt" Font-Names="Microsoft Sans Serif" style="margin:5px"></asp:Label>
                <br />
                <asp:TextBox ID="TextBoxDescription" runat="server" Height="113px" Width="317px" Font-Size="8.25" Font-Names="Microsoft Sans Serif" TextMode="MultiLine" BackColor="#F0F0F0" style="margin:5px" ReadOnly="True">Description :</asp:TextBox>
                <input type="submit" name="OKButton" value="OK" onclick="window.close();" id="OKButton" style="height:21px;width:75px;float:right; margin:5px" />
            </div>
    </form>
</body>
</html>

Aaand here's my AboutBox.aspx.vb file:

Public Class AboutBox
    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

NOTE: I re-made the project under the name "TestAboutBox" since "DemoWebApp" was getting all messed up with me screwing around with stuff.


Solution

  • When you create a new Web Forms page from a Web Application project, it will create the page as described in the question. In order to get it the right way, the Web Form page needs to be made in a Web Site project. This page can then be used elsewhere.