[英]Call class from Web User Control vb.net
I got a class name DataAccess 我有一个类名DataAccess
ie: 即:
Public Class DataAccess
-- some functiom--
End class
I'm creating one Web User Control file name uc_Data 我正在创建一个Web用户控件文件名uc_Data
i can't call DataAccess class from web user control code behind 我无法从后面的Web用户控制代码中调用DataAccess类
Protected Sub Page_Load(sender, ) Handles Me.Load
--want call the class here
End Sub
How to do it? 怎么做?
If you want to call a Shared
function/sub-procedure in the DataAccess
class, then do this: 如果要在
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
If you want to call an instance function/sub-procedure in the DataAccess
class, then do this: 如果要在
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
i found the solution by replace all the class in main project folder instead of put in App_Code folder. 我通过替换主项目文件夹中的所有类而不是放在App_Code文件夹中找到了解决方案。 Then the class can be call from user control page.
然后可以从用户控制页面调用该类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.