How to call code in aspx webform from functions defined in code behind modules

  • Thread starter Thread starter CW
  • Start date Start date
C

CW

I find it necessary to mix code-behind and non-code behind techniques
sometimes.

I have utility functions defined in a VB module. Is there anyway for me to
call functions defined in VB module from aspx form (i.e., code mixed in with
html elements) or even call public shared functions from other code behind
classes)?
 
<%=FunctionName%> in the HTML will call your code-behind function, which
must be defined as Protected.
 
You can access code from code modules, however you must declare the
Module Public and you must qualify the call with the proper namespace.
For example:

in you module:

Public Module Module1
Public Function getString() As String
Return "from module"
End Function
End Module

in your call:

<%=VBTest.Module1.getString()%>

where VBTest is the name of the project or parent namespace of
Module1.

hope this helps,

John
 
Back
Top