This article introduce the Page class of ASP.NET Web Forms and explains some of the useful properties.
Introduction
Every Web Forms page is represented as
an object that inherits from the System.Web.UI.Page base class. This class
contains the methods, properties, and events in the Web Forms page framework.
using System.Web.UI.WebControls;
using System.Web.UI.HTMLControls;
namespace MyNameSpace
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web>UI.Page
{
protected System.Web.UI.WebControls.Calendar Calendar1;
protected System.Web.UI.WebControls.ListBox ListBox1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
private void Page_Load (object sender, System.EventArgs e)
...
...
}
}
The presentation of web pages as
compiled binary code on the server represents a significant improvement from
the scripting model of Active Server Pages (ASP). Another improvement is the
automatic conservation of the page state performed by ASP.NET.
The Page class includes some important
methods and properties.
For example, the ResolveUrl and
HasControls methods are inherited from the Control class. ResolveUrl resolves a
relative URL to an absolute URL and HasControls ascertains if the page contains
any child controls.
ASP.NET allows you to reuse a part of
the Web Form. To do this, you save the relevant part as a user control in a
separate file.
The LoadControl method of the Page class then obtains a UserControl object from
the user control file and loads it.
Here are some of the properties of the
Page class:
·
Application
·
User
·
ClientTarget
·
IsValid
·
ErrorPage
·
Request
· Validators
Application
The Application property returns a reference to the current Application object provided by the HTTP runtime. This object is used to store the Application state.
User
The User property returns a reference to the IPrincipal object that identifies the user making a request. It is a read-only property.
ClientTarget
The ClientTarget property allows you to override the automatic web-browser detection provided by ASP.NET and specify the browser compatibility of the HTML generated from the Web Form page.
IsValid
The IsValid property is True if all the Validator controls in the Web Form succeed.
ErrorPage
The ErrorPage property gets or sets the error page for redirection when an unhandled exception occurs in the page.
Request
The Request property supplies a reference to the corresponding HTTP runtime object. It allows you to get information about and exercise control over the current HTTP session. The same is also true of the Server, Response, and Session properties for their corresponding runtime objects.
Validators
The Validators property returns a collection of all validation controls on the page.
Thanks and Have Fun!!!!!