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>

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";
        }
    }
}

Asp.net Method

Print

Response.Write("Hello World");

POST

Response.Write(Request["name"]);

GET

Response.Write(Request.QueryString["name"]); 

GET – Print all data

for (int idx = 0; idx < Request.QueryString.Count; idx++){  
    Response.Write("Value:" + Request.QueryString[idx]);  
}

Post- Print all data

foreach(string name in Request.Form){
    Response.Write(Request.Form[name]);
}

Include Asp.net

<!--#include file="header.aspx"-->

Include txt

Response.WriteFile("header.aspx");

Redirect

Response.Redirect("index.aspx?message");

Asp.net C# ( GET and POST)

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"/>
    <title></title>
</head>
<body>
    <form id="form1" action="result.aspx" method="get">
        <div>
            <% Response.Write("Hello World"); %><br/>
            <input type="input" name="name" />
            <input type="submit" name="submit">
        </div>
    </form>
</body>
</html>

result.apsx

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

<% 
   Response.Write(Request.QueryString["name"]); // GET
   // Response.Write( Request["name"] );        // POST 
%>