Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access my class from code-behind. Class is App_Code folder

I have a very simple class that is located within my App_Code folder in my VS2008 web application project. I am trying to instantiate an instance of this class from my code-behind file. Intellisense does not seem to be seeing my class and I am not sure why. I am using VB.NET which I am admittedly not that familiar with as compared to C#. Perhaps I am missing something. I would bet it has something to do with something I am missing in VB.NET.

Here is my simple class (for testing):

Public Class mySimpleClass

   'Private member variables whose data is obtained from user input
    Private mUserID as String

   'Class Properties
    Public Property UserID() as Integer
       Get
          Return mUserID
       End Get

       Set(ByVal Value as Integer)
          mUserID = Value
       End Set
    End Property

    'Class Methods
    Public Function DisplayUserID() as String
       Return this.UserID
    End Function

End Class

Here is how I try an instantiate it from the codebehind ...

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim obj As New mySimpleClass()
    End Sub

End Class
like image 939
webworm Avatar asked Feb 15 '11 16:02

webworm


2 Answers

What I ended up doing was deleting my App_Code folder and creating a new "AppCode" folder. I also selected properties for the class file and set the Build Action property to "Compile". Once I did that and recompiled the project my class showed up.

like image 56
webworm Avatar answered Oct 20 '22 01:10

webworm


  1. you should change Return this.UserID to Return Me.UserID (VB.Net ;-))
  2. rebuild the solution and see if it works

I'm not as familiar with the app_code folder and Websites in general, i'm always using WebApplications. I would suggest to convert it to a WebApplication too, here are further informations why: ASP.NET Web Site or ASP.NET Web Application?

like image 23
Tim Schmelter Avatar answered Oct 19 '22 23:10

Tim Schmelter