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


    <title>Hello World!</title>

    <style type="text/css">



        font-family: Verdana, Sans-Serif;

        font-size: 0.8em;






<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




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

<hr />


<hr />




Post a comment

Comments closed