30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 20 ASP .<strong>NET</strong>, Web Forms and Web Controls 1023<br />

The asp: tag prefix in the declaration of a control indicates that the control is an ASP .<strong>NET</strong> Web<br />

control.<br />

Each Web control maps <strong>to</strong> a corresponding HTML element.<br />

The same Web control can map <strong>to</strong> different HTML elements, depending on the client browser and<br />

the Web control’s property settings.<br />

Namespace System.Web contains classes that manage client requests and server responses.<br />

Namespace System.Web.UI contains classes for the creation of Web-based applications and<br />

controls.<br />

Class Page defines a standard Web page, providing event handlers and objects necessary for creating<br />

Web-based applications. All code-behind classes for ASPX forms inherit from class Page.<br />

Class Control is the base class that provides common functionality for all Web controls.<br />

Namespace System.Web.UI.WebControls contains Web controls employed in the design<br />

of the page’s user interface.<br />

Method Page_Init is called when the Init event is raised. This event indicates that the page<br />

is ready <strong>to</strong> be initialized.<br />

The Load event is raised when the page loads. (This event occurs after all the Web controls on<br />

the page have been initialized and loaded.)<br />

When a client requests an ASPX file, a class is created behind the scenes that contains both the<br />

visual aspect of our page (defined in the ASPX file) and the logic of our page (defined in the codebehind<br />

file). This new class inherits from Page. The first time that our Web page is requested, this<br />

class will be compiled, and an instance will be created. This instance represents our page—it will<br />

create the HTML that is sent <strong>to</strong> the client. The assembly created from our compiled class will be<br />

placed in the project’s bin direc<strong>to</strong>ry.<br />

Changes <strong>to</strong> the Web application can be detected by the runtime, and the project is recompiled <strong>to</strong><br />

reflect the altered content.<br />

The Page_Load event handler is usually used <strong>to</strong> execute any processing that is necessary <strong>to</strong> res<strong>to</strong>re<br />

data from previous requests.<br />

After Page_Load has finished executing, the page processes any events raised by the page’s controls.<br />

When a Web Form object is ready for garbage collection, an Unload event is raised. Event handler<br />

Page_Unload is inherited from class Page and contains any code that releases resources.<br />

A form is a mechanism for collecting user information and sending it <strong>to</strong> the Web server.<br />

HTML forms can contain visual and nonvisual components. <strong>Visual</strong> components include clickable<br />

but<strong>to</strong>ns and other graphical user interface components with which users interact.<br />

Nonvisual components in an HTML form, called hidden inputs, s<strong>to</strong>re any data that the document<br />

author specifies.<br />

The name localhost indicates that the client and server reside on the same machine. If the Web<br />

server were located on a different machine, localhost would be replaced with the appropriate<br />

IP address or hostname.<br />

The Web-Form designer can display HTML mode, allowing the programmer <strong>to</strong> view the markup<br />

that represents the user interface of this page. The Design mode allows the programmer <strong>to</strong> view<br />

the page as it will look and modify it using the drag-and-drop technique.<br />

The PageLayout property determines how controls are arranged on the form.<br />

By default, property PageLayout is set <strong>to</strong> GridLayout, which means that all controls remain<br />

exactly where they are dropped on the Web Form. This is called absolute positioning.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!