asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Syntax > ASP.NET Page Syntax > Server-Side Include Directive Syntax

Server-Side Include Directive Syntax

ASP.NET Syntax   ASP.NET Page Syntax


Inserts the contents of a specified file anywhere within an ASP.NET page.

<!-- #include file | virtual  = filename -->

Attributes


File The file name is a physical path from the directory containing the document with the #include directive. This path can be relative.
Virtual The file name is a virtual path from a virtual directory in your Web site. This path can be relative.

NOTE: The included file can be in the same directory or in a subdirectory; it cannot be in a directory above the page with the #include directive.

Remarks

The file name value for the included file must be enclosed in quotation marks ( "" ).

The included file is processed before any dynamic code is executed.

The #include tag must be enclosed within HTML/XML comment delimiters to avoid being interpreted as literal text.

Syntax Example

The below code snippet demonstrates how you can use Server-Side Include Directive Syntax to call files that will create a header and a footer on an ASP.NET page. Both are using relative paths.

<html>
   <body>
      <!-- #include file=header.inc" -->

      Here is the main body of the .aspx file.

      <!-- #include file=footer.inc" -->
   </body>
</html>
includes.aspx
Run Sample | View Source
See Also

Introduction to Web Forms



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note