ASP.NET Tutorial/Language Basics/function — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:00, 26 мая 2010

Create a function (VB)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html>
  <head>
    <title>ASP.NET Functions</title>
    <script runat="server" language="VB">
      Function getName() As String
        Return "a"
      End Function
      Sub Page_Load(s As Object, e As EventArgs) 
        messageLabel.Text = getName()
      End Sub
    </script>
  </head>
  <body>
    <form runat="server">
      <asp:Label id="messageLabel" runat="server" />
    </form>
  </body>
</html>


Define and call function in asp.net page (C#)

<%@ Page Language="C#" %>
<script runat="server">
   void Page_Load(Object Sender, EventArgs e) {
      MultiplyNumbers(8,9);
      MultiplyNumbers(4,12);
      MultiplyNumbers(38,23);
   }
   void MultiplyNumbers(int intA, int intB) {
      Response.Write(intA * intB + "<br>");
   }
</script>
<html><body>
</body></html>


Define function

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>ASP.NET Functions</title>
    <script runat="server" language="C#">
      string getName() 
      {
        return "Abc";
      }
      void Page_Load() 
      {
        messageLabel.Text = getName();
      }
    </script>
  </head>
  <body>
    <form runat="server">
      <asp:Label id="messageLabel" runat="server" />
    </form>
  </body>
</html>


Return value from function (VB)

<%@Page Language="VB" %>
<script runat="server">
sub Page_Load(obj as object,e as eventargs)
    Response.Write(MultiplyNumbers(8,9)&"<br>")
    
    Response.Write(MultiplyNumbers(4,12)&"<br>")
    
    Response.Write(MultiplyNumbers(38,23)&"<br>")
end sub
function MultiplyNumbers(intA as integer,intB as integer) _
as Integer
    Return intA *intB
end function
</script>
<html><body>
</body></html>