asp.netvb.net

Simple ASPX cannot bind to vb.net codebehind


I have this aspx page in my vs 2013 solution:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="PayPalTester._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Source Page</title>
</head>
<body>
    <form id="form1" runat="server">

    </form>
</body>
</html>

And this is my codebehind:

Namespace PayPalTester
    Partial Public Class _Default
        Inherits System.Web.UI.Page

        Protected Sub btnRun_Click(sender As Object, e As EventArgs)

        End Sub

    End Class
End Namespace

When I try to compile I always get the error Could not load type 'PayPalTester._Default'.

If I remove Inherits="PayPalTester._Default" then I don't get that error anymore, but suddenly I get the new error 'btnRun_Click' is not a member of 'ASP.default_aspx'.

These are such simple pages...I normally use c#, but have to use vb.net for this. What am I doing wrong?


Solution

  • Your project was setup as a Web Site project, but your page is configured as a Web Application project. Change your page declaration at the top of your markup from:

    <%@ Page Language="vb" AutoEventWireup="false" 
        CodeBehind="Default.aspx.vb" Inherits="PayPalTester._Default" %>
    

    to:

    <%@ Page Language="vb" AutoEventWireup="false" 
        Codefile="Default.aspx.vb" Inherits="PayPalTester._Default" %>
    

    This MSDN link compares the two.