How to store a function globally and then call the function?

Hello,

I have the following function stored in X.asp.vb and I call it from X.asp (as below). My question is how can I store the function globally so I can call it from multiple .asp pages? I have been reading around this forum and is seems that placing the Function into a .vb class in App_Code is the way to go (which I have tried) The problem is I then don't now how to call it from X.asp Can anybody assist? 

X.asp.vb
Public Function GetFormattedAddress(ByVal val1 As Object, ByVal val2 As Object, ByVal val3 As Object, ByVal val4 As Object, ByVal val5 As Object) As String

X.asp
<a href='CSS2.aspx?PID=<%#Databinder.Eval(Container.DataItem,"PID")%>'>Select</a><%#GetFormattedAddress(Eval("Address1"), Eval("Address2"), Eval("Address3"), Eval("Address4"), Eval("Address5"))%>

Cheers

Marco Gwiliani


Marco Gwiliani

0
marco
7/4/2007 9:00:56 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
678 Views

Similar Articles

[PageSpeed] 59

Create the code/function in a separate code (class) library -

Then, in whatever page you need it, just instantiate the class in your page (code behind)

Dim whatever as new MyCodeLibrary

Then -

label1.text = whatever.MyFunction(your params go here)


David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Please Vote for ASPNet101 - 'Best Community Resource'!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
0
augustwind
7/4/2007 10:09:02 PM

I forgot to mention I am using VWD and so must create a new class in a .vb file placed in the App_Code folder.

Here is an extract from the new class I have created in App_Code, I am unsure how to call this new class (AddressFilter) and the function within it (GetFormattedAddress) from my .asp page (also Below). The code I have below for the .asp works OK when the function is declared in the local .asp.vb page but now I need the function declared globally - ie in a new class within App_Code

AddressFilter.VB
Imports Microsoft.VisualBasic

Public Class AddressFilter

Public Function GetFormattedAddress(ByVal val1 As Object, ByVal val2 As Object, ByVal val3 As Object, ByVal val4 As Object, ByVal val5 As Object) As String

' Declaring a function GetFormattedAddress

 .ASP Page
<a href='CSS2.aspx?PID=<%#Databinder.Eval(Container.DataItem,"PID")%>'>Select</a>

<%#GetFormattedAddress(Eval("Address1"), Eval("Address2"), Eval("Address3"), Eval("Address4"), Eval("Address5"))%>

 

Marco Gwiliani


Marco Gwiliani

0
marco
7/5/2007 6:26:16 AM

in your page's code behind,

Dim af as new AddressFilter
Label1.text=af.GetFormattedAddress(params go here)


David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Please Vote for ASPNet101 - 'Best Community Resource'!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
0
augustwind
7/5/2007 4:13:17 PM

Hello,

I need to call the function from a datalist control on my .asp page, not the .asp.vb page. When the GetFormattedAddress function was stored in my .asp.vb I was able to call it directly in the datalist as below. Now the GetFormattedAddress function is stored in a .vb class file I cannot use this method. I tried to use AddressFilter.GetFormattedAddress (AddressFilter is the name of my class) in the below code but it does not work. Im sure this must be pretty simple, I just cant figure it out. Any Ideas? Cheers Marco

<asp:DataList ID="DataList1" runat="server" Style="font-family: Verdana;font-size: 14px" DataKeyField="PID" DataSourceID="ObjectDataSource1">

<ItemTemplate>

 

<a href='CSS2.aspx?PID=<%#Databinder.Eval(Container.DataItem,"PID")%>'>Select</a>

<%#GetFormattedAddress(Eval("Address1"), Eval("Address2"), Eval("Address3"), Eval("Address4"), Eval("Address5"))%>

 

<br />

</ItemTemplate>

</asp:DataList><br />


Marco Gwiliani

0
marco
7/6/2007 4:43:08 PM

One thing - make it:
Public Shared Function

then, you can use AddressFilter.GetFormattedAddress  -


David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Please Vote for ASPNet101 - 'Best Community Resource'!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
0
augustwind
7/6/2007 5:10:51 PM

Its a hole in one! that works, many thanks augustwind!!!

Regards

Marco Gwiliani


Marco Gwiliani

0
marco
7/6/2007 5:22:55 PM
Reply: