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

4.4k views Asked by At

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.

3

There are 3 answers

1
Filip Ekberg On BEST ANSWER

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()
%>
0
Doug Null On

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

0
Tim On

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.