问题
I can access a module from code behind but not from the aspx page in inline VB code <% ... %>.
I know its got to be something simple but I can't seem to find the answer anywhere.
回答1:
If you want to run a static method from your aspx
you can do something like this:
<% MyNamespace.MyClass.MyMethod() %>
If you want to instancate an object and call a method on that you can do that as well:
<%
Dim obj As MyNamespace.MyClass
obj = New MyNamespace.MyClass()
obj.MyMethod()
%>
回答2:
I find you can also use an Imports Directive as follows at the top of the page:
< % @ Import Namespace="BHSAA.Module1" % >
Where BHSAA was the name of my web app Project and Module1 was , of course my Module with Functions I wanted to call in Code Blocks on my ASPX page.
Your Module and the Functions or Subs in it apparently have to be Public.
Hope that works for you, too.
回答3:
To get MyNameSpace: right-click project > properties > Appl.. tab > Root namespace
'MyClass' is name of the .vb and it MUST have 'public' ie... Public Module MyClass Function MyMethod() Return blah End Function
End Module
来源:https://stackoverflow.com/questions/4960602/how-do-i-access-a-module-or-a-public-class-with-public-shared-members-from-inlin