Session 1 : Session 1 ASP.NET and Web Forms
Objectives : Objectives Explain what is ASP.NET
Configure IIS Settings
Explain Web Forms
Write an ASP.NET application
An Introduction to ASP.NET : An Introduction to ASP.NET ASP.NET is a part of the Microsoft .NET strategy for Web development.
It is a Web development platform that provides the services necessary for developers to build enterprise-class Web applications.
It applies an object-oriented approach to dynamic Web applications.
ASP.NET Web applications are an optimal solution for managing large-scale business applications.
ASP.NET Web applications can be deployed on the Internet or on an intranet.
Advantages of ASP.NET : Advantages of ASP.NET A new development interface under Visual Studio.NET
Separation of code and presentation logic for better understanding and maintenance.
Extensive language support like Visual Basic .NET, C#, Jscript and ADO.NET.
Greater scalability.
Extensive security support.
Efficient state management.
Improved data access using ADO.NET.
Optimizes the performances of request processing by providing extensive caching support.
Easy deployment of applications.
ASP.NET Features 7-1 : ASP.NET Features 7-1 Supports multiple programming languages ASP.NET VB.NET C# JScript Other
languages supports Web Application
ASP.NET Features 7-2 : ASP.NET Features 7-2 Code is Compiled. _______
_______
_______
______ Code Compile Microsoft
Intermediate Language
( MSIL or IL ) JIT compiler Machine language Compiles each portion of IL separately
ASP.NET Features 7-3 : ASP.NET Features 7-3 Improved Caching Support. Cache Full Page Page-level caching – cache a complete page Cache Fragment caching – cache part of a page Part of a Page
ASP.NET Features 7-4 : ASP.NET Features 7-4 ASP.NET is an Object Oriented language and includes a range of useful classes and namespaces. NAMESPACE Class - HtmlAnchor Class - HtmlControl Class - HtmlForm Logically group similar classes that have same
Functionality. Similar functionality
ASP.NET Features 7-5 : ASP.NET Features 7-5 ASP.NET provides several server controls that simplify the task of creating pages. HTML controls belong to the System.Web.UI.HtmlControls namespace and derive from the HtmlControl base class Web Controls Intrinsic
Controls ListBound
Controls Rich
Controls Validation
Controls belong to the System.Web.UI.WebControls namespace and derive from the WebControl base class
ASP.NET Features 7-6 : ASP.NET Features 7-6 ASP.NET allows you to use and create Web services.
A Web service is an application delivered as a service that can be integrated with other Web services by using Internet standards.
Web services provide the building blocks for constructing distributed Web based applications.
Improved Security : ASP.NET allows user authentication methods, code access security and role-based authorization.
ASP.NET Features 7-7 : ASP.NET Features 7-7 Greater Scalability :
session state can be maintained in a separate process on a separate machine or database, allowing for cross-server sessions.
Efficient state management :
Provides support for distributed session state across Web servers.
Easy Configuration and Deployment
Stores configuration information in XML-based configuration files which also makes deployment easier.
ASP.NET Process Flow 3-1 : ASP.NET Process Flow 3-1 ASP.NET File Architecture
ASP.NET Process Flow 3-2 : ASP.NET Process Flow 3-2 ASP.NET File Architecture ( contd..)
ASP.NET Process Flow 3-3 : ASP.NET Process Flow 3-3 Query the Server for web page Interprets .aspx page Compile the page to IL Holds native code versions of pre-compiled pages Stores some items to reduce cost of reconstruction Holds entire pages with object and data
Configuring IIS Settings 2-1 : Configuring IIS Settings 2-1 Internet Information Services (IIS) - Windows Server - based Web service that makes it easy to publish information on your intranet or on the Internet. Installing IIS from Control Panel click Select IIS and click next to configure the components
Configuring IIS Settings 2-2 : Configuring IIS Settings 2-2 A Virtual directory is a logical directory name, used by the Web Server, which corresponds to a physical directory on the server Creating Virtual Directory using IIS Step 1 :
Create Virtual
Directory in
Default Web Site Step 2 :
Give a Virtual
Directory alias Step 3 :
Select the location
Of your
Virtual
Directory Step 4 :
Select the
Appropriate
Access
Permission for
this directory
Web Forms 5-1 : Web Forms 5-1 Web forms are ASP.NET components that enable you to create interactive and dynamic web pages.
Web forms also provide you with a rich set of controls that can be programmed in any .NET-compatible language, such as Visual basic .NET and Visual C#.
Web forms interact with the user to retrieve and update information in the form of Web Pages in the browser.
Properties of Web Forms 5-2 : Properties of Web Forms 5-2 They have a .aspx extension.
They divide Web applications into two parts:
The visual component
The user interface logic.
Web Forms contain code-declaration blocks.
Contain HTML and Server Controls.
They have various directives to control the compilation process.
Properties of Web Forms 5-3 : Properties of Web Forms 5-3 The @Page directive defines page-specific attributes that are used by the ASP.NET page parser and compiler.
A Web form is denoted by the runat="server" attribute e.g. : <%@ Page language="c#" Codebehind="LoginForm.aspx.cs"
AutoEventWireup="false" Inherits="Example1.WebLogionForm" %> e.g :
Web Form Features 5-4 : Web Form Features 5-4 Browser independence is achieved.
Can be programmed in any of the .NET accepted programming languages, including VB.NET, C#, C++.NET, and JScript.NET.
Provide all the benefits of the .NET Framework, including managed code, type safety, and inheritance.
Allow for easy retention of user-entered data while the user is navigating around your Web Site.
Provide a consistent object model for Web Application development.
Web Form Life Cycle 5-5 : Web Form Life Cycle 5-5 Round Trips Web
Form Browser Server Posted to Processed Returned to browser Round trip Page re-created Discards page information
IDE for Web Forms : IDE for Web Forms Web Form IDE Menu bar
And
Toolbar Toolbox Solution Explorer Server
Explorer Properties
Window
Creating a Web Application : Creating a Web Application Building an ASP.NET Web application using Visual C# in the .NET environment. Virtual
Directory is
Created Solution and
Project created as per name provided. The default references and files are also created.
Default Web Application Files : Default Web Application Files
Sample Web Application 3-1 : Sample Web Application 3-1 Drag two Label controls from Web control toolbox Drag two text boxes from Web Control toolbox Drag a button from Web control toolbox Drag a label for displaying message
Sample Web Application 3-2 : Sample Web Application 3-2 private void btnSubmit_Click(object sender, System.EventArgs e)
{
// Checks for null values in the Name field
if((txtName.Text.Trim() == “” || (txtName.Text == null))
{
lblMessage.Text = “Please enter the Name !!”;
}
else
{
// Checks whether the age is between 1 and 100
if ((Convert.ToInt32(txtAge.Text) < 18) || (Convert.ToInt32(txtAge.Text) > 100))
{
lblMessage.Text="Invalid Age !!”;
}
else
{
// Successful authorization and welcome message
lblMessage.Text="Welcome "+txtName.Text;
}
}
} Checks the name text field for null values Checks the value of age between the range Displays welcome message if successful Demonstration: Example 1
Sample Web Application 3-3 : Sample Web Application 3-3 Enter name Enter age Click Submit Welcome message displayed
Summary : Summary ASP.NET is an object-oriented approach that uses the Visual Studio .NET Framework strategy to develop distributed Web applications.
An Internet Information Server is a Windows Server-based Web service to publish information in a network.
A Virtual directory is a logical directory name, used in an address, which corresponds to a physical directory on the server.
Web Forms are ASP.NET components that enable the user to create interactive and dynamic web pages.
There are two types of Server Controls:
HTML Controls
Web Controls
Web Forms divide Web Applications into two pieces:
Code
Components (Code-behind)
A Web form has a .aspx extension.