callison
callison

Reputation: 23

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

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.

Upvotes: 2

Views: 4519

Answers (3)

Doug Null
Doug Null

Reputation: 8327

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

Upvotes: 0

Tim
Tim

Reputation: 11

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.

Upvotes: 1

Filip Ekberg
Filip Ekberg

Reputation: 36297

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()
%>

Upvotes: 1

Related Questions