繁体   English   中英

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

[英]Call class from Web User Control vb.net

我有一个类名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

怎么做?

如果要在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文件夹中找到了解决方案。 然后可以从用户控制页面调用该类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM