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.
ASP.NET
Last Comment
sreerajrs
8/22/2022 - Mon
anoyes
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.
josephdaviskcrm
ASKER
Yes I am calling it by class.method.
How do I import it at the top?
Imports ClassName doesn't work.
nmarun
Please post the namespace of the class you have added. I think you'll have to provide the complete namespace:
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()
sreerajrs
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