How do I access a module or a public class with public shared members from inline vb code <% .. %>

僤鯓⒐⒋嵵緔 提交于 2019-12-11 02:10:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!