The Page class - Web Forms in C# Part 2

Naimishforu
Posted by in C# category on for Beginner level | Points: 250 | Views : 6377 red flag
Rating: 5 out of 5  
 1 vote(s)

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


Page copy protected against web site content infringement by Copyscape

About the Author

Naimishforu
Full Name: Naimish Pandya
Member Level: Bronze
Member Status: Member,MVP
Member Since: 1/22/2011 7:38:35 AM
Country: India
Thanks, Naimish http://dotnetinterview.zxq.net/ http://naimishpandya.blogspot.in/
http://naimishpandya.blogspot.in/

Login to vote for this post.

Comments or Responses

Posted by: Madhu.b.rokkam on: 2/14/2011 | Points: 25
Nice and Informative :)
Posted by: Naimishforu on: 2/14/2011 | Points: 25
Thank you Madhu :)

Thanks

Login to post response

Comment using Facebook(Author doesn't get notification)