Using inline code 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="System" %>
    <script runat="server">
        public string ServerSideFunction(string input)
        {
            return "Hello " + input;
        }
    </script>
</head>
<body>
    <% string pageVariable = "world"; %>
    <% =ServerSideFunction(pageVariable) %>
</body>
</html>

發表迴響