Page level procedure (VB.net) : Function « Language Basics « ASP.Net






Page level procedure (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    If IsPostBack Then
        DisplayInstructions("Final")
    Else
        DisplayInstructions("Initial")
    End If    
End Sub

Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
    lblResult.Text = "Result: " & AddNums( _
        txtNumber1.Text, txtNumber2.Text)
End Sub

Sub DisplayInstructions(Mode as String)
    If Mode = "Initial" Then
      lblInstructions.Text = "Enter two numbers that " _
          & "you want to add."
    Else
      lblInstructions.Text = "The results are " _
          & "below."
    End If
End Sub
Function AddNums(Num1 as Single, Num2 as Single) as Single
   AddNums = Num1 + Num2
End Function
</script>
<HTML>
<HEAD>
<TITLE>Creating Your Own Procedures</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<asp:label
    id="lblInstructions" 
    runat="server"
/>
<BR><BR>
Enter a number:<BR>
<asp:textbox 
    id="txtNumber1" 
    runat=server 
/>
<BR><BR>
Enter a second number:<BR>
<asp:textbox 
    id="txtNumber2" 
    runat=server 
/>
<BR><BR>
<asp:button 
    id="butOK"
    text="Add"
    onclick="SubmitBtn_Click" 
    runat="server"
/>
<BR><BR>
<asp:label
    id="lblResult" 
    runat="server"
/>
</Form>
</BODY>
</HTML>
           
       








Related examples in the same category

1.Define and call function in a page (VB.net)
2.Define function to change 'HR' length (C#)
3.Function Parameter passed by Reference (C#)
4.Function Parameter passed by Value (C#)
5.Using out Parameters (C#)
6.Simple function without parameters (C#)
7.Define and call function (C#)
8.Call function (C#)
9.Function local variable (C#)