C#: Using inline code in ASP.NET

Using this syntax, you can use inline code in ASP.NET (.aspx) pages. The server-side code will be automatically compiled by the .NET framework the first time the page is requested on the server. The compiled .dll file is stored in the "Temporary ASP.NET Files" system folder. Changing the code in .aspx files will trigger a new compilation, generating new .dll files. The old .dll files are phased out by the framework and eventually deleted.

 

<%@ Import Namespace="System" %>

<%@ Page Language="c#"%>

 

<script runat="server">

  public string ServerSideFunction(string input)

  {

    return "Hello " + input;

  }

</script>

 

<% string pageVariable = "world"; %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />

<title>ASP.NET inline</title>

</head>

<body>

<% =ServerSideFunction(pageVariable) %>

</body>

</html>