0% found this document useful (0 votes)
5 views

aspdotnet

Uploaded by

Dinesh R Balaji
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

aspdotnet

Uploaded by

Dinesh R Balaji
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 62

ASP.

NET
• ASP stands for Active Server Pages
• ASP is a development framework for building web pages.
• ASP and ASP.NET are server side technologies.
• Both technologies enable computer code to be executed by an
Internet server.
• When a browser requests an ASP or ASP.NET file, the ASP engine
reads the file, executes any code in the file, and returns the result to
the browser.
Classic ASP - Active Server Pages

• ASP was introduced in 1998 as Microsoft's first server side scripting


language.
• Classic ASP pages have the file extension .asp and are normally
written in VBScript.
ASP.NET

• ASP.NET was released in 2002 as a successor to Classic ASP.


• ASP.NET pages have the extension .aspx and are normally written in
C# (C sharp).
• ASP.NET 4.6 is the latest official version of ASP.NET.
ASP.NET Web Pages

• ASP.NET Web Pages is an SPA application model (Single Page


Application).
• The SPA model is quite similar to PHP and Classic ASP.
• ASP.NET Web Pages is being merged into the new ASP.NET Core.
ASP.NET

• It is a web framework designed and developed by Microsoft.


• It is used to develop websites, web applications and web services
• It is built on the Common Language Runtime (CLR) and allows
programmers to write code using any supported .NET language.
ASP.NET Page Lifecycle
• In ASP.NET, a web page has execution lifecycle that includes various
phases. These phases include initialization, instantiation, restoring
and maintaining state etc.
Stage Description
Page request This stage occurs before the lifecycle begins. When a page is requested
by the user, ASP.NET parses and compiles that page.
Start In this stage, page properties such as Request and response are set. It
also determines the Request type.
Initialization In this stage, each control's UniqueID property is set. Master page is
applied to the page.
Load During this phase, if page request is postback, control properties are
loaded with information.
Postback In this stage, event handler is called if page request is postback. After
event that, the Validate method of all validator controls is called.
handling
Rendering Before rendering, view state is saved for the page and all controls.
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 At this stage the requested page has been fully rendered and is ready to
terminate.at this stage all properties are unloaded and cleanup is
performed.
ASP.NET Life Cycle Events
Page Event Typical Use
PreInit This event is raised after the start stage is complete and before the initialization
stage.
Init This event occurs after all controls have been initialized.
We can use this event to read or initialize control properties.
InitComplete This event occurs at the end of the page's initialization stage.
We can use this event to make changes to view state that we want to make sure are
persisted after the next postback.
PreLoad This event is occurs before the post back data is loaded in the controls.
Load This event is raised for the page first time and then recursively for all child controls.

Control events This event is used to handle specific control events such as Button control' Click
event.
LoadComplete This event occurs at the end of the event-handling stage.
We can use this event for tasks that require all other controls on the page be loaded.

PreRender This event occurs after the page object has created all controls that are required in
order to render the page.
PreRenderComplet This event occurs after each data bound control whose DataSourceID property is set
e calls its DataBind method.
SaveStateComplet It is raised after view state and control state have been saved for the page and for all
e controls.
Render This is not an event; instead, at this stage of processing, the Page object calls this
method on each control.
ASP.NET Web Forms
• Web Forms are web pages built on the ASP.NET Technology.
• It executes on the server and generates output to the browser.
• It is compatible to any browser to any language supported by .NET
common language runtime.
• It is flexible and allows us to create and add custom controls.
• We can use Visual Studio to create ASP.NET Web Forms. It is an IDE
(Integrated Development Environment) that allows us to drag and
drop server controls to the web forms.
• It also allows us to set properties, events and methods for the
controls. To write business logic, we can choose any .NET language
like: Visual Basic or Visual C#.
• Web Forms are made up of two components: the visual portion (the
ASPX file), and the code behind the form, which resides in a separate
class file.
• ASP.NET provides various controls like: server controls and HTML
controls for the Web Forms.
Server Controls
Control Name Applicable Events Description
Label None It is used to display text on the HTML page.
TextBox TextChanged It is used to create a text input in the form.
Button Click, Command It is used to create a button.
LinkButton Click, Command It is used to create a button that looks similar to the hyperlink.

ImageButton Click It is used to create an imagesButton. Here, an image works as a Button.

Hyperlink None It is used to create a hyperlink control that responds to a click event.

DropDownList SelectedIndexChanged It is used to create a dropdown list control.

ListBox SelectedIndexCnhaged It is used to create a ListBox control like the HTML control.

DataGrid CancelCommand, EditCommand, DeleteCommand, It used to create a frid that is used to show data. We can also perform
ItemCommand, SelectedIndexChanged, PageIndexChanged, paging, sorting, and formatting very easily with this control.
SortCommand, UpdateCommand, ItemCreated,
ItemDataBound

DataList CancelCommand, EditCommand, DeleteCommand, It is used to create datalist that is non-tabular and used to show data.
ItemCommand, SelectedIndexChanged, UpdateCommand,
ItemCreated, ItemDataBound

Repeater ItemCommand, ItemCreated, ItemDataBound It allows us to create a non-tabular type of format for data. You can bind
the data to template items, which are like bits of HTML put together in a
specific repeating format.

CheckBox CheckChanged It is used to create checkbox.


CheckBoxList SelectedIndexChanged It is used to create a group of check boxes that all work together.

RadioButton CheckChanged It is used to create radio button.


RadioButtonList SelectedIndexChanged It is used to create a group of radio button controls that all work
together.
HTML Controls
Controls Name Description
Button It is used to create HTML button.
Reset Button Resets all other HTML form elements on a form to a default value

Submit Button Automatically POSTs the form data to the specified page listed in the Action
attribute in the FORM tag

Text Field Gives the user an input area on an HTML form


Text Area Used for multi-line input on an HTML form
File Field Places a text field and a Browse button on a form and allows the user to select
a file name from their local machine when the Browse button is clicked

Password Field An input area on an HTML form, although any characters typed into this field
are displayed as asterisks

CheckBox Gives the user a check box that they can select or clear
Radio Button Used two or more to a form, and allows the user to choose one of the controls

Table Allows you to present information in a tabular format

Image Displays an image on an HTML form


ASP.NET Web Forms Project
• Creating a new project
• Click on the file menu from the menu bar and select new -> project.
• Select Project type
• It provides couple of choices but we selecting ASP.NET Web
Application.
• Select Project Template
• After selecting project types, now, it asks for the type of template that
we want to implement in our application.
After clicking ok, it shows project
in solution explorer window that
looks like the below.
This project contains a default.aspx file which is a
startup file. When we run the project this file executes
first and display a home page of the site.
Create a New Web Form
Select web forms option in left corner and then select web form and hit
add button.
Double click on user form and this will show some auto generated code
like this:
user-form.aspx
• <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="user-form.aspx.cs"
• Inherits="asp.netexample.user_form" %>
• <!DOCTYPE html>
• <html xmlns="http://www.w3.org/1999/xhtml">
• <head runat="server">
• <title></title>
• </head>
• <body>
• <form id="form1" runat="server">
• <div>
• </div>
• </form>
• </body>
• </html>
• <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="user-form.aspx.cs"
• Inherits="asp.netexample.user_form" %>
• <!DOCTYPE html>
• <html xmlns="http://www.w3.org/1999/xhtml">
• <head runat="server">
• <title></title>
• </head>
• <body>
• <form id="form1" runat="server">
• <div>
• <h2>Welcome to the Web Forms!</h2>
• </div>
• </form>
• </body>
• </html>
After running it on the browser
Components of .Net Framework
• (1) Common Language Runtime or CLR
• It performs memory management, exception handling, debugging,
security checking, thread execution, code execution, code safety,
verification, and compilation.
• The code that is directly managed by the CLR is called the managed
code.
• When the managed code is compiled, the compiler converts the
source code into a CPU independent intermediate language (IL) code.
• A Just In Time(JIT) compiler compiles the IL code into native code,
which is CPU specific.
(2) .Net Framework Class Library
It contains a huge library of reusable types. classes, interfaces,
structures, and enumerated values, which are collectively called types.

(3) Common Language Specification


It contains the specifications for the .Net supported languages and
implementation of language integration.

(4) Common Type System


It provides guidelines for declaring, using, and managing types at
runtime, and cross-language communication.
(5) Metadata and Assemblies
Metadata is the binary information describing the program, which is
either stored in a portable executable file (PE) or in the memory.
Assembly is a logical unit consisting of the assembly manifest, type
metadata, IL code, and a set of resources like image files.

(6) Windows Forms


Windows Forms contain the graphical representation of any window
displayed in the application.
(7) ASP.NET and ASP.NET AJAX
ASP.NET is the web development model and AJAX is an extension of ASP.NET for
developing and implementing AJAX functionality. ASP.NET AJAX contains the
components that allow the developer to update data on a website without a
complete reload of the page.

(8) ADO.NET
It is the technology used for working with data and databases. It provides access
to data sources like SQL server, OLE DB, XML etc. The ADO.NET allows
connection to data sources for retrieving, manipulating, and updating data.

(9) Windows Workflow Foundation (WF)


It helps in building workflow-based applications in Windows. It contains
activities, workflow runtime, workflow designer, and a rules engine.
(10) Windows Presentation Foundation
It provides a separation between the user interface and the business logic. It
helps in developing visually stunning interfaces using documents, media, two and
three dimensional graphics, animations, and more.

(11) Windows Communication Foundation (WCF)


It is the technology used for building and executing connected systems.

(12) Windows CardSpace


It provides safety for accessing resources and sharing personal information on the
internet.

(13) LINQ
It imparts data querying capabilities to .Net languages using a syntax which is
similar to the tradition query language SQL.
ASP.NET - Example
• An ASP.NET page is made up of a number of server controls along
with HTML controls, text, and images.
• ASP.NET runtime controls the association between a page instance
and its state.
• An ASP.NET page is an object of the Page or inherited from it.
• All the controls on the pages are also objects of the related control
class inherited from a parent Control class.
• When a page is run, an instance of the object page is created along
with all its content controls.
• An ASP.NET page is modular in nature and can be divided into the
following core sections:
• Page Directives
• Code Section
• Page Layout
Page Directives
• The page directives set up the environment for the page to run.
• The @Page directive defines page-specific attributes used by ASP.NET
page parser and compiler.
• Page directives specify how the page should be processed, and which
assumptions need to be taken about the page.
• It allows importing namespaces, loading assemblies, and registering
new controls with custom tag names and namespace prefixes.
Code Section
• It provides the handlers for the page and control events along with
other functions required.
• ASP.NET follows an object model, these objects raise events when
some events take place on the user interface, like a user clicks a
button or moves the cursor.
• The event handlers are nothing but functions bound to the controls.
• The code section or the code behind file provides all these event
handler routines, and other functions used by the developer.
• The page code could be precompiled and deployed in the form of a
binary assembly.
Page Layout
• The page layout provides the interface of the page.
• It contains the server controls, text, inline JavaScript, and HTML tags.
• <!-- Layout -->
• <!-- directives --> • <html>
• <% @Page Language="C#" %> • <head>
• <title> Change to Upper Case </title>
• </head>
• <!-- code section -->

• <script runat="server"> • <body>
• <h3> Conversion to Upper Case </h3>

• private void convertoupper(object
sender, EventArgs e) • <form runat="server">
• <input runat="server" id="mytext" type="text" />
• { • <input runat="server" id="button1" type="submit"
• string str = mytext.Value; value="Enter..." OnServerClick="convertoupper"/>
• changed_text.InnerHtml = str.ToUpper(); •
• <hr />
• } • <h3> Results: </h3>
• </script> • <span runat="server" id="changed_text" />
• </form>


• </body>
Using Visual Studio IDE
• drag the controls into the design view:
• The content file is automatically developed.
• add the Button1_Click routine,

• protected void Button1_Click(object sender, EventArgs e)


•{
• string buf = TextBox1.Text;
• changed_text.InnerHtml = buf.ToUpper();
•}
The content file code is
• <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
• Inherits="firstexample._Default" %>
• <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
• <html xmlns="http://www.w3.org/1999/xhtml" >
• <head runat="server">
• <title>
• Untitled Page
• </title>
• </head>
• <body>
• <form id="form1" runat="server">
• <div>
• <asp:TextBox ID="TextBox1" runat="server" style="width:224px">
• <br /> <br />
• <asp:Button ID="Button1" runat="server" Text="Enter..." style="width:85px" onclick="Button1_Click" />
• <hr />
• <h3> Results: </h3>
• <span runat="server" id="changed_text" /
• </div>
• </form>
• </body>
• </html>
ASP.NET - Deployment
• There are two categories of ASP.NET deployment:
• Local deployment : In this case, the entire application is contained
within a virtual directory and all the contents and assemblies are
contained within it and available to the application.
• Global deployment : In this case, assemblies are available to every
application running on the server.
• There are different techniques used for deployment
• the following most common and easiest ways of deployment:
• XCOPY deployment
• Copying a Website
• Creating a set up project
XCOPY Deployment
• XCOPY deployment means making recursive copies of all the files to
the target folder on the target machine.
• FTP transfer
• Using Server management tools that provide replication on a remote site
• MSI installer application
• XCOPY deployment simply copies the application file to the production server
and sets a virtual directory there.
• Copying a Website
• The Copy Web Site option is available in Visual Studio. It is available
from the Website -> Copy Web Site menu option.
• This menu item allows copying the current web site to another local
or remote location.
• It is a sort of integrated FTP tool.
• Using this option, you connect to the target destination, select the
desired copy mode:
• Overwrite
• Source to Target Files
• Sync UP Source And Target Projects
Creating a Setup Project
• In this method, you use Windows Installer and package your web
applications so it is ready to deploy on the production server.
• Visual Studio allows you to build deployment packages.
• Open the project and take the following steps:
• Step (1) : Select File -> Add -> New Project with the website root
directory highlighted in the Solution Explorer.
• Step (2) : Select Setup and Deployment, under Other Project Types.
Select Setup Wizard.
• Step (3) : Choosing the default location ensures that the set up
project will be located in its own folder under the root directory of
the site. Click on okay to get the first splash screen of the wizard.
• Step (4) : Choose a project type. Select 'Create a setup for a web
application'.
• Step (5) : Next, the third screen asks to choose project outputs from
all the projects in the solution. Check the check box next to 'Content
Files from...'
• Step (6) : The fourth screen allows including other files like ReadMe.
However, in our case there is no such file. Click on finish.
• Step (7) : The final screen displays a summary of settings for the set
up project.
• Step (8) : The Set up project is added to the Solution Explorer and the
main design window shows a file system editor.
• Step (9) : Next step is to build the setup project. Right click on the
project name in the Solution Explorer and select Build.
• Step (10) : When build is completed, you get the following message in
the Output window:

• Two files are created by the build process:


• Setup.exe
• Setup-databinding.msi
• You need to copy these files to the server. Double-click the setup file
to install the content of the .msi file on the local machine.

You might also like