Export (0) Print
Expand All
6 out of 16 rated this helpful - Rate this topic

Server-Side Include Directive 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.
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.
Virtual
The file name is a virtual path from a virtual directory in your Web site. This path can be relative.
Note   This technique is recommended because of potential changes in the physical path to a file.

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.

Example

The following example 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 virtual=".\include\header.inc" -->
      Here is the main body of the .aspx file.
      <!-- #Include virtual=".\include\footer.inc" -->
   </body>
</html>

See Also

Introduction to Web Forms Pages | ASP.NET Web Forms Syntax

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.