从Web用户控件vb.net调用类



我得到了一个类名DataAccess

即:

Public Class DataAccess
-- some functiom--
End class

我正在创建一个名为uc_Data 的Web用户控制文件

我无法从后面的web用户控制代码调用DataAccess类

Protected Sub Page_Load(sender, ) Handles Me.Load
--want call the class here
End Sub

怎么做?

如果要调用DataAccess类中的Shared函数/子过程,请执行以下操作:

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

我通过替换主项目文件夹中的所有类而不是放在App_Code文件夹中找到了解决方案。然后可以从用户控制页面调用该类。

最新更新