+ All Categories
Home > Documents > PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side...

PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side...

Date post: 04-Oct-2020
Category:
Upload: others
View: 6 times
Download: 0 times
Share this document with a friend
22
PS03CINTO4 || ASP.NET || UNIT: I BHAVIN PATEL Page 1 What is ASP.Net? ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model, a comprehensive software infrastructure and various services required to build up robust web application for PC, as well as mobile devices.ASP.NET is run inside the IIS(Internet Information Services). ASP.Net works on top of the HTTP protocol and uses the HTTP commands and policies to set a browser-to-server two-way communication and cooperation. The ASP.Net application codes could be written in either of the following languages: C# Visual Basic .Net Jscript J# ASP.Net is used to produce interactive, data-driven web applications over the internet. It consists of a large number of controls like text boxes, buttons and labels for assembling, configuring and manipulating code to create HTML pages. Advantages of ASP.NET 1. Separation of Code from HTML To make a clean sweep, with ASP.NET you have the ability to completely separate layout and business logic. This makes it much easier for teams of programmers and designers to collaborate efficiently. This makes it much easier for teams of programmers and designers to collaborate efficiently. 2. Support for compiled languages Developer can use VB.NET and access features such as strong typing and object- oriented programming. Using compiled languages also means that ASP.NET pages do not suffer the performance penalties associated with interpreted code. ASP.NET pages are precompiled to byte-code and Just In Time (JIT) compiled when first requested. Subsequent requests are directed to the fully compiled code, which is cached until the source changes. 3. Use services provided by the .NET Framework The .NET Framework provides class libraries that can be used by your application. Some of the key classes help you with input/output, access to operating system
Transcript
Page 1: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 1

What is ASP.Net?

ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model, a comprehensive software infrastructure and various services required to build up robust web application for PC, as well as mobile devices.ASP.NET is run inside the IIS(Internet Information Services).

ASP.Net works on top of the HTTP protocol and uses the HTTP commands and policies to set a browser-to-server two-way communication and cooperation.

The ASP.Net application codes could be written in either of the following languages:

C# Visual Basic .Net Jscript J#

ASP.Net is used to produce interactive, data-driven web applications over the internet. It consists of a large number of controls like text boxes, buttons and labels for assembling, configuring and manipulating code to create HTML pages.

Advantages of ASP.NET

1. Separation of Code from HTML

To make a clean sweep, with ASP.NET you have the ability to completely separate layout and business logic. This makes it much easier for teams of programmers and designers to collaborate efficiently. This makes it much easier for teams of programmers and designers to collaborate efficiently.

2. Support for compiled languages

Developer can use VB.NET and access features such as strong typing and object-oriented programming. Using compiled languages also means that ASP.NET pages do not suffer the performance penalties associated with interpreted code. ASP.NET pages are precompiled to byte-code and Just In Time (JIT) compiled when first requested. Subsequent requests are directed to the fully compiled code, which is cached until the source changes.

3. Use services provided by the .NET Framework

The .NET Framework provides class libraries that can be used by your application. Some of the key classes help you with input/output, access to operating system

Page 2: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 2

services, data access, or even debugging. We will go into more detail on some of them in this module.

4. Graphical Development Environment

Visual Studio .NET provides a very rich development environment for Web developers. You can drag and drop controls and set properties the way you do in Visual Basic 6. And you have full IntelliSense support, not only for your code, but also for HTML and XML.

5. State management

State information can be kept in memory or stored in a database. It can be shared across Web forms, and state information can be recovered, even if the server fails or the connection breaks down.

6. Update files while the server is running

Components of your application can be updated while the server is online and clients are connected. The Framework will use the new files as soon as they are copied to the application. Removed or old files that are still in use are kept in memory until the clients have finished.

7. XML-Based Configuration Files

Configuration settings in aASP.NET are stored in XML files that you can easily read and edit. You can also easily copy these to another server, along with the other files that comprise your application.

NET Framework Architecture

The Microsoft .Net Framework is a platform that provides tools and technologies.

The primary types of application development are:

Web Forms,

Web Services, and

Windows Forms applications.

Page 3: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 3

A .NET Framework having two main components:

1. Common Language Runtime (CLR) 2. Base Class Library (BCL) / Framework Class Library (FCL)

A .NET Framework having another two components are:

3. Common Type System ( CTS ) 4. Common Language Specification ( CLS )

1. Common Language Runtime:

It is the execution engine for .NET Framework applications.

It is the runtime engine provided by the .NET framework.

It serves as the interface between .NET applications and the operating system.

It provides an infrastructure for running programs and allows them to communicate

with other parts of the .NET framework.

It provides number of services, including the following:

1. Code loading and execution

2. Memory management

Page 4: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 4

3. Exception handling

4. Access to metadata

5. Access security

6. Conversion of IL into native code

Language Runtime (CLR) manages the execution of code compiled for the .NET

platform The Common

The CLR has two features:

1. Its specification has been opened up so that it can be ported to non-Windows

platforms.

2. Any number of different languages can be used to manipulate the .NET framework

classes, and the CLR will support them.

Common Language Runtime (CLR) Compilation:

As a developer you can write code in the language of your choice.

Your code is compiled into an Assembly, which is represented as a DLL or EXE.

2) Framework Class Library ( FCL ) / Base Class Library (BCL):

It is also known as a base class library. The FCL is a collection of over 7000

reusable classes, interfaces. .Net Use this classes for:

a) read and write files,

b) access databases,

Page 5: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 5

c) process XML,

d) display a graphical user interface,

e) draw graphics,

f) Use Web services, etc.

The .Net Framework class library (FCL) organized in a hierarchical tree structure

and it is divided into Namespaces. Namespaces is a logical grouping of classes

having similar functionality. Framework class library (FCL) provides the consistent

base types that are used across all .NET enabled languages. The Classes are accessed

by namespaces, which reside within Assemblies.

System is the root of namespace.

Example: System.IO System.DATA

3) Common Type System ( CTS )

1) CTS allow programs written in different programming languages to easily share

information.

2) A class written in C# should be equivalent to a class written in VB.NET.

3) Languages must agree on the meanings of these concepts before they can

integrate with one and other.

4) CLS forms a subset of Common type system this implies that all the rules that for

apply to Common type system apply to common language specification.

5) It defines rules that a programming language must follow to ensure that objects

written in different programming languages can interact which each other.

6) Common type system provide cross language integration.

The common type system supports two general categories of types:

a) Value Type

b) Reference Type

Page 6: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 6

The Value Types are passed by values and stored value directly in the stack.

The Reference Types are passed by references and stored in the managed heap.

4) Common Language Specification ( CLS )

The CLS is a common platform that integrates code and components from multiple .NET

programming languages.

In other words, a .NET application can be written in multiple programming languages with

no extra work by the developer.

CLS includes basic Language features needed by almost all the application.

It serves as a guide for Library Writers and Compiler Writer.

The Common Language Specification is a subset of the common type system (CTS).

The common language specification is also important to application to who are

writing codes that will be used by other developers.

CLS a series of basic rules that are required for language integration.

Microsoft Intermediate Language – MSIL

MSIL stands for Microsoft Intermediate Language.

We can call it as Intermediate Language (IL) or Common Intermediate Language

(CIL).

During the compile time, the compiler convert the source code into Microsoft

Intermediate Language (MSIL) .

Microsoft Intermediate Language (MSIL) is a CPU-independent set of instructions

that can be efficiently converted to the native code.

During the runtime the Common Language Runtime (CLR)'s Just in Time (JIT)

compiler converts the Microsoft Intermediate Language (MSIL) code into native

code to the Operating System.

Page 7: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 7

When a compiler produces Microsoft Intermediate Language (MSIL), it also

produces Metadata.

The Microsoft Intermediate Language (MSIL) and Metadata are contained in a

portable executable (PE) file

Microsoft Intermediate Language (MSIL) includes:

1. Instructions for loading, storing, initializing, and calling methods on objects.

2. As well as instructions for arithmetic and logical operations, control flow, direct

memory access, exception handling, and other operations.

Features: It contain code that CLR-executers.

It forms a security boundary it means it is a unit at which permission are required &

granted.

Advantages: It offers cross language integration.

It does automatic memory management.

Compilation is must quicker

It allows you to compile code once and then run it on any CPU and operating system

that support at run-time.

Disadvantages: MSIL is not compiling to machine so it can easily be reverse engine.

Large amount of algorithm are required to manage system resource and hardware.

Metadata Metadata stored within the Assembly.

.NET records information about compiled classes as Metadata.

Page 8: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 8

Metadata means data about data.

A .NET language compiler will generate the metadata and store this in the assembly.

Metadata is nothing but a description of every namespace, class, method, property

etc contained within the PE( Portable Executable) file.

Microsoft Intermediate Language (MSIL) is a CPU-independent set of instructions

that can be efficiently converted to the native code.

During the runtime the Common Language Runtime (CLR)'s Just in Time (JIT)

compiler converts the Microsoft Intermediate Language (MSIL) code into native

code to the Operating System.

The CLR uses this metadata to

Locate classes

Load classes

Generate native node

Provide security

Assembly: An assembly is the primary building blocks of a .NET framework application.

An assembly having extension .DLL or .EXE.

Metadata stored within the Assembly. It means Information about compiled classes

records in Assembly.

It is a collection of functionality that is built, versioned and deployed as a single

implementation unit.

All managed types and resources are marked either as accessible only within their

implementation unit or as accessible by code outside that unit.

Page 9: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 9

Figure 3 : A diagram of assembly

It contains the code that the runtime executes.

It forms a security boundary. An assembly is the unit at which permissions are

requested and granted.

It forms a type boundary. Every type’s identity includes the name of the assembly

at which it resides.

It forms a reference scope boundary. The assembly's manifest contains assembly

metadata that is used for resolving types and satisfying resource requests.

Assemblies are made up of the following parts:

a) The assembly manifest

It contains the assembly information such as the assembly’s version, security,

identity, and references to other assemblies.

b) Type metadata

Metadata provides information about all the types defined in the assembly

such as classes, interface, properties, methods, events, and so on.

c) Microsoft Intermediate Language (MSIL) code

This is the Microsoft Intermediate Language code. MSIL code is executed by

CLR.

There are two types of assemblies.

1. Private assemblies:

A private assembly is used only by a single application, and is stored in that

application’s install directory.

Private assemblies are not designed to be shared.

Page 10: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 10

By default, all assemblies are private.

If you wish to make them shared, you must explicitly do so by signing them.

It is expected that the majority of assemblies you create will be of the private type.

2. Public assemblies:

A shared assembly is one that can be referenced by more than one application.

Shared Assemblies are kept in Global Assembly Cache. Client application using

Shared Assemblies need not have its own copy of dll.

Shared Assemblies are present in C:\WINDOWS\assembly folder.

ASP.NET Controls

The ASP.NET Framework contains more than 90 controls. These controls can be divided into seven groups:

Standard Controls— Enable you to render standard form elements such as buttons, input fields, and labels.

They are server side objects. They are programmable objects that act as user interfaces(UI) elements on a web page. The class of these controls is System.Web.UI.WebControls.

Syntax:

<asp:Button ID="Button1" runat="server" Text="Button" />

Page 11: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 11

Validation Controls— Enable you to validate data before you submit the data to the server. For example, you can use a RequiredFieldValidator control to check whether a user entered a value for a required input field.

Validation Controls are attached to input controls to test the data the user enters into it. They are used to test the input.

Rich Controls— Enable you to render things such as calendars, file upload buttons, rotating banner advertisements, and multistep wizards.

Data Controls— Enable you to work with data such as database data. For example, you can use these controls to submit new records to a database table or display a list of database records.

Navigation Controls— Enable you to display standard navigation elements such as menus, tree views, and bread crumb trails.

Login Controls— Enables you to display login, change password, and registration forms.

Page 12: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 12

HTML Controls— Enable you to convert any HTML tag into a server-side control.

ASP.Net Page Life Cycle

Stage Description

Page request

The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled or whether a cached version of the page can be sent in response without running the page.

Start In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property.

Initialization During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable.

Load During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.

Postback event handling

If the request is a postback, control event handlers are called.

Rendering During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream object of the page's Response property.

Unload The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.

Page 13: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 13

ASP.Net Page Life Cycle Events:

Page Event Typical Use

PreInit

Raised after the start stage is complete and before the initialization stage begins.

Use this event for the following: Create or re-create dynamic controls. Set a master page dynamically. Set the Theme property dynamically. Read or set profile property values.

Init

Raised after all controls have been initialized and any skin settings have been applied. The Init event of individual controls occurs before the Init event of the page.

Use this event to read or initialize control properties.

InitComplete Raised at the end of the page's initialization stage.

PreLoad

Raised after the page loads view state for itself and all controls, and after it processes postback data that is included with the Request instance.

Load

Use the OnLoad event method to set properties in controls and to establish database connections.

Control events Use these events to handle specific control events, such as a Button control's Click event or a TextBox control's TextChanged event.

LoadComplete

Raised at the end of the event-handling stage.Use this event for tasks that require that all other controls on the page be loaded.

PreRender

Raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls. Use the event to make final changes to the contents of the page or its controls before the rendering stage begins.

PreRenderComplete

Raised after each data bound control whose DataSourceID property is set calls its DataBind method.

SaveStateComplete

Raised after view state and control state have been saved for the page and for all controls.

Render

This is not an event; instead, at this stage of processing, the Page object calls this method on each control. All ASP.NET Web server controls have a Render method that writes out the control's markup to send to the browser.

Page 14: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 14

Unload

Raised for each control and then for the page.

In controls, use this event to do final cleanup for specific controls, such as closing control-specific database connections.

For the page itself, use this event to do final cleanup work, such as closing open files and database connections, or finishing up logging or other request-specific tasks.

ASP.NET Application Directories App_Browsers ASP.net reserve this folder name for storing browser definition

files. Browser definition files are used to determine the client browser capabilities. Browser definition files have .browser extension.

App_code App_code folder can contain source code for utility classes as well business objects (.cs, .vb and .jsl files). Classes that are present in App_Code folder are automatically complied when your web application complied.

App_data App_Data is used to store file that can be used as database files (.mdf and xml files).

App_GlobalResources App_GlobalResources folder contains resources (.resx and .resources files) that are compiled into assemblies and have a global scope.

App_localResources App_LocalResources folder contains resources (.resx and .resources files). The same files that are being contained by App_GlobalResources but files located in this folder are only available to a particular project, web page, master page or web user control.

App_Themes Contain subfolders that each defines a specific theme or look and feel for you Web site. A these consist of files (such as .skin, .css and image files) that defines the appearance of Web pages and controls.

App_webreferences Contains Web references files (.wsdl, .xsd, .disco, and .discomap files) that define references to Web services.

Bin Bin folder contains compiled assemblies (.dll files) for code that you want to reference in your application. Assemblies in Bin folder are automatically reference in your application.

Page 15: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 15

ASP.Net Directives

Directives specify settings that are used by the page and user-control compilers when the compilers process ASP.NET Web Forms pages (.aspx files) and user control (.ascx) files.

ASP.NET treats any directive block (<%@ %>) that does not contain an explicit directive name as an @ Page directive (for a page) or as an @ Control directive (for a user control).

For syntax information and descriptions of the attributes that are available for each directive, use the links that are listed in the following table.

Directive Description

@ Assembly Links an assembly to the current page or user control declaratively.

@ Control

Defines control-specific attributes used by the ASP.NET page parser and compiler and can be included only in .ascx files (user controls).

@ Implements

Indicates that a page or user control implements a specified .NET Framework interface declaratively.

@ Import Imports a namespace into a page or user control explicitly.

@ Master

Identifies a page as a master page and defines attributes used by the ASP.NET page parser and compiler and can be included only in .master files.

@ MasterType

Defines the class or virtual path used to type the Master property of a page.

@ OutputCache

Controls the output caching policies of a page or user control declaratively.

@ Page

Defines page-specific attributes used by the ASP.NET page parser and compiler and can be included only in .aspx files.

@ PreviousPageType

Creates a strongly typed reference to the source page from the target of a cross-page posting.

@ Reference

Links a page, user control, or COM control to the current page or user control declaratively.

@ Register

Associates aliases with namespaces and classes, which allow user controls and custom server controls to be rendered when included in a requested page or user control.

ASP.Net directives are instructions to specify optional settings, such as registering a custom control and page language. These settings describe how the web forms (.aspx) or user controls (.ascx) pages are processed by the .Net framework.

The syntax for declaring a directive is:

Page 16: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 16

<%@ directive_name attribute=value [attribute=value] %>

In this section, we will just introduce the ASP.Net directives and we will use most of these directives throughout the tutorials.

1. The Application Directive

The Application directive defines application-specific attributes. It is provided at the top of the global.asax file.

The basic syntax for a sample Application directive is:

<%@ Application Language="C#" %>

The attributes of the Application directive are:

Attributes Description

Inherits the name of the class from which to inherit

Description text description of the application. Parsers and compilers ignore this

Language language used in code blocks

2. The Assembly Directive

The Assembly directive links an assembly to the page or the application at parse time. This could appear either in the global.asax file for application-wide linking or in the page file or a user control file for linking to a page or user control.

The basic syntax for a sample Assembly directive is:

<%@ Assembly Name ="myassembly" %>

The attributes of the Assembly directive are:

Attributes Description

Name the name of the assembly to be linked

Page 17: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 17

Src the path to the source file to be linked and compiled dynamically

3. The Control Directive

The Control directive is used with the user controls and appears in the user control (.ascx) files.

The basic syntax for a sample Control directive is:

<%@ Control Language="C#" EnableViewState="false" %>

The attributes of the Control directive are:

Attributes Description

AutoEventWireup the Boolean value that enables or disables automatic association of events to handlers

ClassName file name for the control

Debug the Boolean value that enables or disables compiling with debug symbols

Description text description of the control page, ignored by compiler

EnableViewState the Boolean value that indicates whether view state is maintained across page requests

Explicit for VB language, tells the compiler to use Option Explicit mode

Inherits the class from which the control page inherits

Language language for code and script

Src the filename for the code-behind class

Strict for VB language, tells the compiler to use the Option Strict mode

4. The Implements Directive

The Implement directive indicates that the web page, master page or user control page must implement the specified .Net framework interface.

The basic syntax for an Implements directive is:

Page 18: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 18

<%@ Implements Interface="interface_name" %>

5. The Import Directive

The Import directive imports a namespace into a web page, user control page of application. If the Import directive is specified in the global.asax, then it will apply to the entire application. If it is in a page of user control page, then it would apply to that page or control.

The basic syntax for an Import directive is:

<%@Import namespace="System.Drawing" %>

6. The Master Directive

The Master directive specifies a page file as being the mater page.

The basic syntax for a sample MasterPage directive is:

<%@ MasterPage Language="C#" AutoEventWireup="true" CodeFile="SiteMater.master.cs" Inherits="SiteMaster" %>

7. The MasterType Directive

The MasterType directive assigns a class name to the Master property of a page, to make it strongly typed.

The basic syntax for a MasterType directive is:

<%@ MasterType attribute="value"[attribute="value" ...] %>

8. The OutputCache Directive

The OutputCache directive controls the output caching policies of a web page or a user control.

The basic syntax for a OutputCache directive is:

Page 19: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 19

<%@ OutputCache Duration="15" VaryByParam="None" %>

9. The Page Directive

The Page directive defines the attributes specific to the page file for the page parser and the compiler.

The basic syntax for a Page directive is:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Trace="true" %>

The attributes of the Page directive are:

Attributes Description

AutoEventWireup the Boolean value that enables or disables Page events that are being automatically bound to methods; for example, Page_Load

ClassName class name for the page

CodeFile name of the code behind file

Debug the Boolean value that enables or disables compilation with debug symbols

EnableSessionState enables, disables or makes session state read-only

EnableViewState the Boolean value that enables or disables view state across page requests

ErrorPage URL for redirection if an unhandled page exception occurs

Inherits the name of the code behind or other class

Language programming language for code

Src file name of the code behind class

Trace enables or disables tracing

10. The PreviousPageType Directive

The PreviousPageType directive assigns a class to a page, so that the page is strongly typed.

The basic syntax for a sample PreviousPagetype directive is:

Page 20: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 20

<%@ PreviousPageType attribute="value"[attribute="value" ...] %>

The Reference Directive

The Reference directive indicates that another page or user control should be compiled and linked to the current page.

The basic syntax for a sample Reference directive is:

<%@ Reference Page ="somepage.aspx" %>

11. The Register Directive

The Register derivative is used for registering the custom server controls and user controls.

The basic syntax for a sample Register directive is:

<%@ Register Src="~/footer.ascx" TagName="footer" TagPrefix="Tfooter" %>

Page 21: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 21

What is IsPostBack?

Postback is actually sending all the information from client to web server, then web server

process all those contents and returns back to the client. Most of the time ASP control will

cause a post back (e. g. buttonclick) but some don't unless you tell them to do In certain

events ( Listbox Index Changed,RadioButton Checked etc..) in an ASP.NET page upon which

a PostBack might be needed.

IsPostBack is a property of the Asp.Net page that tells whether or not the page is on its

initial load or if a user has perform a button on your web page that has caused the page to

post back to itself. The value of the Page.IsPostBack property will be set to true when the

page is executing after a postback, and false otherwise. We can check the value of this

property based on the value and we can populate the controls on the page.

Is Postback is normally used on page _load event to detect if the web page is getting

generated due to postback requested by a control on the page or if the page is getting

loaded for the first time.

C# Source Code

protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // generate form;

Page 22: PS03CINTO4 || ASP.NET || UNIT: I · ASP.NET is the advanced version of ASP. It is a server side technology. ASP.Net is a web development platform, which provides a programming model,

PS03CINTO4 || ASP.NET || UNIT: I

BHAVIN PATEL Page 22

} }

Web.config File

ASP.NET Web.config allows you to define or revise the configuration settings at the time of developing the application or at the time of deployment or even after deployment.

The Web.config file contains information that controls module loading, security configuration, session state configuration, and application language and compilation settings.

Web.config files can also contain application specific items such as database connection strings.

The following are brief points that can be understood about the Web.config file:

Web.config files are stored in XML format which makes us easier to work with. You can have any number of Web.config files for an application.

Each Web.config applies settings to its own directory and all the child directories below it.

The changes in Web.config don’t require the reboot of the web server. Example:

<configuration> <configSections> <sectionGroup> </sectionGroup> </configSections> <system.web> </system.web> <connectionStrings> </connectionStrings> <appSettings> </appSettings> </configuration>


Recommended