Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP.NET Web Pages Objects

ASP.NET Web Pages - Objects


Web Pages are often related to objects.


Page Object

You have already seen some Page object methods in use:

@RenderPage("header.cshtml")

@RenderBody()

In previous chapters, you have seen two Page object properties (isPost and Request):

If (isPost) {

if (Request["Choice"] != null ) {


Some Page Object Methods

Method Description
href Creates a URL using the specified values.
RenderBody() Renders a portion of a content page that is not in a named section of the layout page.
RenderPage(page) Renders the content of one page within another page.
RenderSection(section) Renders the content of a named section of the layout page.
Write(object) Writes an object as an HTML-encoded string.
WriteLiteral Writes an object without HTML encoding preferentially.

Some Page Object Properties

property Description
isPost Returns true if the client used the POST method for the HTTP data transfer.
Layout Gets or sets the path of the layout page.
Page Provides property-like access to data shared between the page and the layout page.
Request Gets the HttpRequest object for the current HTTP request.
Server Gets the HttpServerUtility object, which provides web page handling methods.

The Page Property of the Page Object

The Page property of the Page object provides property-like access to data shared between the page and the layout page.

You can add your own properties to the Page property:

Page properties are very useful. For example, set the page title in the content file and use it in the layout file:

Home.cshtml

@{
Layout="~/Shared/Layout.cshtml";
Page.Title="Home Page"
}

Welcome to runoob.com

Web Site Main Ingredients

A Home Page (Default.cshtml)

A Layout File (Layout.cshtml)

A Style Sheet (Site.css)

Layout.cshtml

<p>@Page.Title</p>

@RenderBody()