Search code examples
asp.netcode-behind

CodeFile OK, CodeBehind gives "not declared" error


I have an asp project that works fine with CodeFile, but when I change it to CodeBehind, the vb functions are not recognized in the aspx file, giving a "Name ... is not declared" error in the aspx file.

In order to use CodeBehind, is there something else that should be done besides changing codefile to codebehind in the top line?

The following code gets the error "Name 'connex' is not declared," in the aspx file.

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="browse.aspx.vb" Inherits="_browse" %> <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head runat="server"> <title>Test</title> </head> 
<body> 
<form id="form1" runat="server">
<div>
<%
  Dim s As String = connex()  
  Response.Write(s)
%>
</div>
</form>
</body>
</html>

==================

Imports System
Imports System.Web

Partial Public Class _browse
Inherits System.Web.UI.Page

Function connex() As String
  Return "OK"
End Function

End Class

Solution

  • Check your

    Inherits="_browse"
    

    Make sure to include the correct namespace.

    Inherits="MyNameSpace._browse"