josephdaviskcrm
asked on
Cannot access class in a vb.net web application
I'm building a vb.net web application and I've added a class to the project in the App_Code directory. Now I am not able to access the class to call any of it's methods. I know this is something very simple, I just can't seem to figure it out.
Are you calling them by Class.Method, or just Method? If you're just calling Method, then you need to import the class using Imports Class at the top of your code-behind file.
ASKER
Yes I am calling it by class.method.
How do I import it at the top?
Imports ClassName doesn't work.
How do I import it at the top?
Imports ClassName doesn't work.
Please post the namespace of the class you have added. I think you'll have to provide the complete namespace:
Imports [project's namespace].App_Code
Imports [project's namespace].App_Code
Or you can call this class as:
Dim myClass as App_Code.MyClass
myClass = new AppCode.MyClass
Dim myClass as App_Code.MyClass
myClass = new AppCode.MyClass
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi josephdaviskcrm,
Make sure that you have declared your class as public.
You can access only shared members with out instanciation.
Case 1:
Public Class Class1
Shared Function calclulate(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
Public Function HelloWorld() As String
Return "HelloWorld"
End Function
End Class
You may call the first method as
Class1.calculate(10,10)
and the second one as
dim objClass as new Class1
objClass.HelloWorld()
Make sure that you have declared your class as public.
You can access only shared members with out instanciation.
Case 1:
Public Class Class1
Shared Function calclulate(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
Public Function HelloWorld() As String
Return "HelloWorld"
End Function
End Class
You may call the first method as
Class1.calculate(10,10)
and the second one as
dim objClass as new Class1
objClass.HelloWorld()
Just adding up to the above solution. Also check whether both you class and your webform are in same namespace else you need to use an import statement