我有一个类名DataAccess
即:
Public Class DataAccess
-- some functiom--
End class
我正在创建一个Web用户控件文件名uc_Data
我无法从后面的Web用户控制代码调用DataAccess类
Protected Sub Page_Load(sender, ) Handles Me.Load
--want call the class here
End Sub
怎么做?
答案 0 :(得分:0)
如果要在Shared
课程中调用DataAccess
函数/子过程,请执行以下操作:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
' Do not need to new up an instance,
' just call method by name prefixed by class name
DataAccess.DoSomething()
End Sub
如果要在DataAccess
类中调用实例函数/子过程,请执行以下操作:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
' Need to new up an instance of the class and then you can
' call a method from that instance
Dim theDataAccess As New DataAccess()
theDataAccess.DoSomething2()
End Sub
答案 1 :(得分:0)
我通过替换主项目文件夹中的所有类而不是放在App_Code文件夹中找到了解决方案。然后可以从用户控制页面调用该类。