Call class method in ASP.net C#

index.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="project.WebForm1" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <%@ Import Namespace="project" %>
    <title></title>
</head>
<body>
    <% 
        Response.Write(HelloWorld.helloMethod());
    %>
    <form id="form1" action="index.aspx" method="get">
        <div>
            <input type="input" name="name" />
            <input type="submit" name="submit">
        </div>
    </form>
</body>
</html>

HelloWorld.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace project
{
    public class HelloWorld
    {
        public static string helloMethod()
        {
            return "Hello World";
        }
    }
}

發表迴響