function.aspx
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
' Set values for our labels
lblValue1.Text = 534
lblValue2.Text = 3142
' Add values together using our function to get the
' result which we then assign to the result label.
lblResult.Text = Add(lblValue1.Text, lblValue2.Text)
End Sub
' This function takes two integers and ads them together.
Function Add(intA As Integer, intB As Integer)
' Declare a variable to store the result.
' Since it was declared inside the function
' you can only access this variable while
' you're inside the function.
Dim intResult
' Do our calculation and store the result.
intResult = intA + intB
' Set our return value by assigning it
' to the function's name.
Add = intResult
End Function
</script>
<html>
<head>
<title>ASP.NET Function Sample</title>
</head>
<body>
<p>Here are a couple examples of calling the function:</p>
<h2>Method 1 - just like "classic ASP"</h2>
<p>1 + 2 = <%= Add(1, 2) %></p>
<hr />
<h2>Method 2 - Page_OnLoad</h2>
<p>
<asp:Label id="lblValue1" runat="server" />
+ <asp:Label id="lblValue2" runat="server" />
= <asp:Label id="lblResult" runat="server" />
</p>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/function_aspx.asp">here</a>
to read about and download the source code.
</p>
</body>
</html>