Embedded Code Blocks in ASP.NET Web Pages

An embedded code block is server code that executes during the page's render phase. The code in the block can execute programming statements and call functions in the current page class. The following code example shows an ASP.NET page with an embedded code block.

<%@ Page Language="VB" %>

<!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" >

<head>

    <title>Hello World!</title>

    <style type="text/css">

    body

    {

        font-family: Verdana, Sans-Serif;

        font-size: 0.8em;

    }

    </style>

</head>

<body>

 

<script runat="server">

   

    Public myVar As String = String.Empty

    Private myString As String = String.Empty

   

    Sub Page_Load()

        myVar = "Some value..."

        Call MySub()

    End Sub

   

    Sub MySub()

        myString = "This is my string!"

    End Sub

 

    </script>

 

<% Response.Write(DateTime.Now())%>

<hr />

<%=myVar%>

<hr />

<%=myString%>

</body>

</html>

Post a comment

Comments closed