Working with Web Forms in ASP.NET

Web Forms in ASP.NET:

Web Form is an ASP.NET technology that we use to create a programmable Web page. It can present information, using any markup language, to the user in any browser, and can use code on the server to implement application logic.

Characteristics of Web Forms in ASP.NET:

1. A Web-form of your design can run on a specific browser of your choice, or it can run on any browser and automatically render the browser-compliant HTML.

2. It is built on the Common Language Runtime, thereby providing a managed execution environment, type safety, inheritance, and dynamic compilation. It can be programmed in any CLR-supported language.

3. It supports WYSIWYG editing tools and development tools such as VS.NET.

4. It supports a rich set of controls that enables you to encapsulate page logic into reusable components and declaratively handle page events.

5. It allows for separation between code and content on a page.

6. It provides a set of state management features that preserves the view state of a page between requests.

A Web-form may contain directives, server-side scripts, client-side scripts, static texts, Web controls, HTML controls, etc.

Page directives:

It is used to set various attributes about a page. The ASP Engine and the compiler follow these directives to prepare a page. There are many kinds of directives.
[html]@ Page,@ Import,@Implements,
@ Register,@ OutputCache and
@ Assembly directives

List of Page Directives and their functions:

@ Page: We may use this directive to declare many page-related attributes about a particular page.
[html]<%@ Page Language=” VB” Debug=” true” %>
There are numerous attributes of this directive. Some of the frequently used ones are these:
[html]AutoEventWireup, Buffer, ClientTarget, EnableSessionState, ErrorPage, Debug, Trace, TraceMode[/html], and so on.

@ Import: We use this directive to import a namespace in the page class file. we are importing the [html]System.Data.OleDb[/html] namespace in our page:
[html]<%@ Import Namespace=”System.Data.OleDb” %>

@ OutputCache: We can use this directive to specify how to cache the page.
[html]%@ OutputCache Duration=”10” /%>

@ Register: This directive is used to register a custom control in a page.
[html]<%@ Register tagprefix =”utoledo” tagname=”Time” Src=”TimeUserControl.ascx”%>

@ Assembly: We use this directive to link an assembly to the current page or user control.
[html]<%@ Assembly Name=”Payroll” %>

@ Implements: This directive enables us to implement an interface on our page. we are implementing the [html]IpostBackEventHandler[/html] interface in one of our user controls: