SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
Introduction to ASP.NET
Web programming
Week 11, day2
Web programming
ASP.NET Overview & Features
 ASP.NET provides services to allow the creation, deployment, and
execution of
Web Applications and Web Services
 Web Applications are built using Web Forms
 Built on .NET Framework: any .NET programming language can be
used (C#, Visual Basic)
 Complete object model
 Separation of code and UI
 Maintains page state
 Session management
ASP.NET with HTML
• separation between markup and code - .aspx & .aspx.vb/ .aspx.cs
files
•Inline asp code can be inserted inside HTML as in case of PHP with
“<% ‘this is asp.net code %>” tags
•Double clicking on each control generates the most used event
handler for that control in the code behind file
•The page directive
•The runat = “server” attribute for server controls
Lets jump into coding
An example application
This is intented to walk you through creating a simple application using asp.net,
visual studio an C#
The application takes the time from the web server and shows it on an aspx page
To create a new application follow the steps in the previous tutorial(ppt)
Following the instructions in the previous tutorial create a new C# application
named ‚webtime‛ in visual studio.
an ASPX file (i.e., Web Form), default named Default.aspx is created for each new
project.
Visual Web Developer creates a code-behind file named Default.aspx.cs.
Example Application - Webtime
• the solution explorer inside visual studio shows the folder structure of your
project and the toolbox shows a list of available .net controls those can be added to
your webpage. (Please explore the ‚view‛ tab if any or both of these are not
shown in the VS window)
•When the project loads for the first time, the Web Forms Designer displays the
auto generated ASPX file in Source mode.
•Design mode indicates the XHTML element where the cursor is currently
located.
•You can also view both the markup and the web-page design at the same time by
using Split mode
•Right click the ASPX file in the Solution Explorer and select View Code to open
the code-behind file.
Renaming and editing the aspx file
Let’s create our first ASP.NET page using Visual Studio
1. Modify title of the page
2. Add a heading <h2>
3. Look at the page in Design and Split modes
4. Add a Label control from the Toolbox
5. Change ID of the Label control
6. Change some physical properties of the Label control
7. Go to Default.aspx.cs file and add Page_Init function to set Text property of
the Label control
Editing & adding controls to the aspx file
Changing the Title of the Page
•We change the page’s title from the default Untitled Page to A Simple Web Form
•Open the ASPX file in Source mode and modify the text between the <title> tags.
•Alternatively, you can modify the Web Form’s Title property in the Properties
window.
•To view the Web Form’s properties, select DOCUMENT from the drop-down list in
the Properties window.
Designing the Page
•To add controls to the page, you can drag and drop them from the Toolbox onto the
Web Form in Design mode.
•Like the Web Form itself, each control is an object that has properties, methods and
events.
•You can type text directly on a Web Form at the cursor location or insert XHTML
elements using menu commands.
Editing & adding controls to the aspx file
Renaming the ASPX File
 Right click the ASPX file in the Solution Explorer and select Rename.
 Enter the new file name WebTime.aspx and press Enter. Both the ASPX file and the
code-behind file are updated.
Renaming the Class in the Code-Behind File and Updating the ASPX File
Visual Studio’s refactoring tool, automatically updates the existing references to this
class in the rest of the project to reflect this change.
Check the ‚code file‛ attribute in the page directive in the .aspx file for correctness
(it should have the new file name)
Editing & adding controls to the aspx file
Visual Studio generates the markup shown when you create the GUI.
11
1 <%-- WebTime.aspx --%>
2 <%-- A page that displays the current time in a Label. --%>
3 <%@ Page Language="C#" AutoEventWireup="true"
CodeFile="WebTime.aspx.cs"
4 Inherits="WebTime" EnableSessionState="False" %>
5
6 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
7 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
8
9 <html xmlns="http://www.w3.org/1999/xhtml">
10 <head runat="server">
11 <title>A Simple Web Form Example</title>
12 </head>
13 <body>
14 <form id="form1" runat="server">
15 <div>
16 <h2>Current time on the web server:</h2>
ASP.NET comments
begin with <%-- and
terminate with --%>,
and can span multiple
lines.
The Page directive
specifies information
needed by ASP.NET
to process this file.
ASPX file that displays the web server’s time.
The document type
declaration, which specifies
the document element name
and the PUBLIC URI for the
DTD that defines the
XHTML vocabulary.
XHTML documents
have the root element
html and markup
information about the
document in the head
element.
The body contains
the main content
that the browser
displays.
The form that contains our
XHTML text and controls is set
to execute on the server, which
generates equivalent XHTML.
Visual Studio generates the markup shown when you create the GUI.
17 <p>
18 <asp:Label ID="timeLabel" runat="server" BackColor="Black"
19 Font-Size="XX-Large" ForeColor="Yellow"
20 EnableViewState="False"></asp:Label>
21 </p>
22 </div>
23 </form>
24 </body>
25 </html>
Markup for a label
web control.The asp: tag prefix
indicates that the
label is an ASP.NET
web control, not an
XHTML element.
• In an ASPX file a directive is delimited by <%@ and %>.
Examining the aspx file
• The Page directive’s Language attribute specifies the
code-behind file’s language.
• The CodeFile attribute specifies the code-behind filename.
• When AutoEventWireup is true, ASP.NET automatically treats a method of
name Page_eventName as an event handler.
• When AutoEvent-Wireup is set to false, you specify event handlers using
attributes in the Page directive just as you would any other web control.
• The Inherits attribute (line 4) specifies the class in the code-behind file from
which this ASP.NET class inherits.
Examining the aspx file
• Setting the runat attribute to "server" indicates that ASP.NET processes the
element and its nested elements and generates the corresponding XHTML.
• The body contains the main content that the browser displays.
• The form that contains our XHTML text and controls is set to execute on
the server, which generates equivalent XHTML.
• The ID attribute assigns a name to a control, used as an identifier in the
code-behind file.
• The asp: tag prefix indicates that the label is an ASP.NET web control, not
an XHTML element.
• Each web control maps to a corresponding XHTML element or group of
elements.
The code-behind file (WebTime.aspx.cs)
1 // WebTime.aspx.cs
2 // Code-behind file for a page that displays the current time.
3 using System;
4
5 public partial class WebTime : System.Web.UI.Page
6 {
7 // initializes the contents of the page
8 protected void Page_Init( object sender, EventArgs e )
9 {
10 // display the server's current time in timeLabel
11 timeLabel.Text = DateTime.Now.ToString( "hh:mm:ss" );
12 } // end method Page_Init
13 } // end class WebTime
Code-behind file for a page that displays
the web server’s time. (Part 1 of 2.)
The Page_Init
method handles the
page’s Init event,
which indicates that
the page is ready to
be initialized.
Retrieve the current
time and formats it
as hh:mm:ss.
WebTime.aspx Example run
• The Page_Init method handles the page’s Init event, which indicates
that the page is ready to be initialized.
Relationship Between an ASPX File and a
Code Behind File
• The code-behind file inherits from Page, which defines the general
functionality of a web page.
• The code-behind file contains a partial class.
• The first time the web page is requested, this class is compiled, and an
instance is created.
• This instance represents our page—it creates the XHTML that is sent to the
client.
How the Code in an ASP.NET Web Page Executes
When an instance of the page is created, the PreInit event occurs first,
invoking method Page_PreInit, which can be used to set a page’s theme.
The Init event occurs next, invoking method Page_Init, which is used to
initialize objects and other aspects of the page.
Next, the Load event occurs, and the Page_Load event handler executes.
 The Init event is raised only once (when the page is first requested).
 The Load event is raised with every request.
 The page then processes any events that are generated by the page’s controls.
 Once a response has been generated and sent, an Unload event occurs,
which calls Page_Unload, which typically releases resources used by the
page.
How HTML is rendered by asp.net
• To view the XHTML generated by ASP.NET, select View Source option in
the browser
• Nonvisual form components, called hidden inputs, store data that the user
doesn’t need to see.
• Attribute method of the form element specifies the request method (usually
get or post). The action attribute identifies the resource that will be
requested when a form is submitted.
XHTML generated by ASP.NET when a web browser
requests WebTime.aspx.
1 <!-- WebTime.html -->
2 <!-- The XHTML generated when WebTime.aspx is loaded. -->
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
4 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
5
6 <html xmlns="http://www.w3.org/1999/xhtml">
7 <head>
8 <title>A Simple Web Form Example</title>
9 </head>
10 <body>
11 <form method="post" action="WebTime.aspx" id="form1">
12 <div>
13 <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=
14 "/wEPDwUJODExMDE5NzY5ZGQ4n4mht8D7Eqxn73tM5LDnstPlCg==" />
15 </div>
Nonvisual form
components,
called hidden
inputs, store data
that the user
doesn’t need to
see.
Attribute method
of the form
element specifies
the request method
(usually get or
post). The
action attribute
identifies the
resource that will
be requested when
a form is
submitted.
XHTML generated by ASP.NET when a web browser
requests WebTime.aspx.
16
17 <div>
18 <h2>Current time on the web server:</h2>
19 <p>
20 <span id="timeLabel" style="color:Yellow;
21 background-color:Black;font-size:XX-Large;">
22 03:11:49
23 </span>
24 </p>
25 </div>
26 </form>
27 </body>
28 </html>
The form contains a
span element to
represent the text in
the label. Formatting
properties of time
Label are converted
into the style
attribute of the span
element.
Running the program
• You can view the Web Form several ways.
– You can select Debug > Start Without Debugging, which runs the
application by opening it in a browser window.
– To debug your application, you can select Debug > Start Debugging.
You cannot debug a web application unless debugging is explicitly
enabled by the web.config file.
– To view a specific ASPX file, you can right click either the Web Forms
Designer or the ASPX file name and select View In Browser.
– Finally, you can run your application by opening a browser window and
typing the web page’s URL in the Address field.
Event handling
• GUIs are event driven.
• When the user interacts with a GUI component, a corresponding event is
raised (eg. Click of a button)
• A method that performs a task in response to an event is called an event
handler.
Event handling example
• Let’s create another ASP.NET page using Visual Studio
1. Add a Button and a Label control (label id = labelHello)
2. To create this click event handler, double click the Button on the Form.
3. The following empty event handler is declared:
4. Set the Text property of the Label control with the current time in this
function.
protected void Button1_Click(object sender, EventArgs e)
{
labelHello.Text = "Hello World! Time is " + DateTime.Now;
}
‘Where Button1 is the unique id of the element
Event handling example
• To add an event handler, alternatively in markup (aspx) file:
1. Add a onclick="BClick" property to the Button control.
2. Add a function BClick to the page class in the code behind.
Event handling
• By convention, C# names the event-handler method as
objectName_eventName (e.g., Button1_Click).
• Each event handler receives two parameters when it is called:
– An object reference named sender—a reference to the object that
generated the event.
– A reference to an object of type EventArgs, which contains additional
information about the event.
• Typically, controls can generate many different types of events.
• Clicking the Events icon (the lightning-bolt icon) in the Properties window,
displays all the events for the selected control.
End of Day
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

Contenu connexe

Tendances

Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentRob Windsor
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...SharePoint Saturday NY
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Rob Windsor
 
Programming web application
Programming web applicationProgramming web application
Programming web applicationaspnet123
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16Vivek chan
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20HUST
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaJignesh Aakoliya
 
SharePoint 2010 Client Object Model
SharePoint 2010 Client Object ModelSharePoint 2010 Client Object Model
SharePoint 2010 Client Object ModelG. Scott Singleton
 
Ajax control tool kit
Ajax control tool kitAjax control tool kit
Ajax control tool kitVidhi Patel
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.netSireesh K
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05Vivek chan
 

Tendances (20)

Controls
ControlsControls
Controls
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
 
Programming web application
Programming web applicationProgramming web application
Programming web application
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
 
ASP
ASPASP
ASP
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20
 
ASP.NET Web form
ASP.NET Web formASP.NET Web form
ASP.NET Web form
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
 
Lecture2
Lecture2Lecture2
Lecture2
 
Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Ajax and ASP.NET AJAX
Ajax and ASP.NET AJAXAjax and ASP.NET AJAX
Ajax and ASP.NET AJAX
 
SharePoint 2010 Client Object Model
SharePoint 2010 Client Object ModelSharePoint 2010 Client Object Model
SharePoint 2010 Client Object Model
 
Ajax control tool kit
Ajax control tool kitAjax control tool kit
Ajax control tool kit
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.net
 
Introduction to asp
Introduction to aspIntroduction to asp
Introduction to asp
 
DEVICE CHANNELS
DEVICE CHANNELSDEVICE CHANNELS
DEVICE CHANNELS
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05
 

En vedette

Technical screening .Net Developer
Technical screening  .Net DeveloperTechnical screening  .Net Developer
Technical screening .Net DeveloperTom Henricksen
 
Introducing asp.net web pages 2
Introducing asp.net web pages 2Introducing asp.net web pages 2
Introducing asp.net web pages 2Uh-meet Thapa
 
Directives in asp.net
Directives in asp.netDirectives in asp.net
Directives in asp.netSireesh K
 
Custom controls
Custom controlsCustom controls
Custom controlsaspnet123
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.NetHitesh Santani
 
ASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateMindfire Solutions
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life CycleAbhishek Sur
 
Intro To Asp Net And Web Forms
Intro To Asp Net And Web FormsIntro To Asp Net And Web Forms
Intro To Asp Net And Web FormsSAMIR BHOGAYTA
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsIdo Flatow
 
ASPX Session xi(page lifecycle)
ASPX Session xi(page lifecycle)ASPX Session xi(page lifecycle)
ASPX Session xi(page lifecycle)Shrijan Tiwari
 

En vedette (13)

Technical screening .Net Developer
Technical screening  .Net DeveloperTechnical screening  .Net Developer
Technical screening .Net Developer
 
Introducing asp.net web pages 2
Introducing asp.net web pages 2Introducing asp.net web pages 2
Introducing asp.net web pages 2
 
Directives in asp.net
Directives in asp.netDirectives in asp.net
Directives in asp.net
 
Custom controls
Custom controlsCustom controls
Custom controls
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
 
ASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewState
 
Ch3 server controls
Ch3 server controlsCh3 server controls
Ch3 server controls
 
ASP.NET Web Security
ASP.NET Web SecurityASP.NET Web Security
ASP.NET Web Security
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 
Intro To Asp Net And Web Forms
Intro To Asp Net And Web FormsIntro To Asp Net And Web Forms
Intro To Asp Net And Web Forms
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
ASPX Session xi(page lifecycle)
ASPX Session xi(page lifecycle)ASPX Session xi(page lifecycle)
ASPX Session xi(page lifecycle)
 

Similaire à ASP.NET - Web Programming

ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1Neeraj Mathur
 
Aspnet architecture
Aspnet architectureAspnet architecture
Aspnet architecturephantrithuc
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.netshan km
 
Asp.net architecture
Asp.net architectureAsp.net architecture
Asp.net architectureIblesoft
 
SharePoint 2007 Presentation
SharePoint 2007 PresentationSharePoint 2007 Presentation
SharePoint 2007 PresentationAjay Jain
 
Active server pages
Active server pagesActive server pages
Active server pagesmcatahir947
 
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)Prof Ansari
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questionsAkhil Mittal
 
How to develop asp web applications
How to develop asp web applicationsHow to develop asp web applications
How to develop asp web applicationsDeepankar Pathak
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentChui-Wen Chiu
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentalsGopal Ji Singh
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web ApplicationRishi Kothari
 

Similaire à ASP.NET - Web Programming (20)

Creating web form
Creating web formCreating web form
Creating web form
 
Creating web form
Creating web formCreating web form
Creating web form
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1
 
Ajax
AjaxAjax
Ajax
 
Aspnet architecture
Aspnet architectureAspnet architecture
Aspnet architecture
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
 
Asp.net architecture
Asp.net architectureAsp.net architecture
Asp.net architecture
 
Asp.net w3schools
Asp.net w3schoolsAsp.net w3schools
Asp.net w3schools
 
As pnet
As pnetAs pnet
As pnet
 
SharePoint 2007 Presentation
SharePoint 2007 PresentationSharePoint 2007 Presentation
SharePoint 2007 Presentation
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Active server pages
Active server pagesActive server pages
Active server pages
 
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
 
How to develop asp web applications
How to develop asp web applicationsHow to develop asp web applications
How to develop asp web applications
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
 
SynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax DevelopmentSynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax Development
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
NET_Training.pptx
NET_Training.pptxNET_Training.pptx
NET_Training.pptx
 

Plus de baabtra.com - No. 1 supplier of quality freshers

Plus de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Dernier

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

ASP.NET - Web Programming

  • 1. Introduction to ASP.NET Web programming Week 11, day2
  • 3. ASP.NET Overview & Features  ASP.NET provides services to allow the creation, deployment, and execution of Web Applications and Web Services  Web Applications are built using Web Forms  Built on .NET Framework: any .NET programming language can be used (C#, Visual Basic)  Complete object model  Separation of code and UI  Maintains page state  Session management
  • 4. ASP.NET with HTML • separation between markup and code - .aspx & .aspx.vb/ .aspx.cs files •Inline asp code can be inserted inside HTML as in case of PHP with “<% ‘this is asp.net code %>” tags •Double clicking on each control generates the most used event handler for that control in the code behind file •The page directive •The runat = “server” attribute for server controls
  • 5. Lets jump into coding An example application
  • 6. This is intented to walk you through creating a simple application using asp.net, visual studio an C# The application takes the time from the web server and shows it on an aspx page To create a new application follow the steps in the previous tutorial(ppt) Following the instructions in the previous tutorial create a new C# application named ‚webtime‛ in visual studio. an ASPX file (i.e., Web Form), default named Default.aspx is created for each new project. Visual Web Developer creates a code-behind file named Default.aspx.cs. Example Application - Webtime
  • 7. • the solution explorer inside visual studio shows the folder structure of your project and the toolbox shows a list of available .net controls those can be added to your webpage. (Please explore the ‚view‛ tab if any or both of these are not shown in the VS window) •When the project loads for the first time, the Web Forms Designer displays the auto generated ASPX file in Source mode. •Design mode indicates the XHTML element where the cursor is currently located. •You can also view both the markup and the web-page design at the same time by using Split mode •Right click the ASPX file in the Solution Explorer and select View Code to open the code-behind file. Renaming and editing the aspx file
  • 8. Let’s create our first ASP.NET page using Visual Studio 1. Modify title of the page 2. Add a heading <h2> 3. Look at the page in Design and Split modes 4. Add a Label control from the Toolbox 5. Change ID of the Label control 6. Change some physical properties of the Label control 7. Go to Default.aspx.cs file and add Page_Init function to set Text property of the Label control Editing & adding controls to the aspx file
  • 9. Changing the Title of the Page •We change the page’s title from the default Untitled Page to A Simple Web Form •Open the ASPX file in Source mode and modify the text between the <title> tags. •Alternatively, you can modify the Web Form’s Title property in the Properties window. •To view the Web Form’s properties, select DOCUMENT from the drop-down list in the Properties window. Designing the Page •To add controls to the page, you can drag and drop them from the Toolbox onto the Web Form in Design mode. •Like the Web Form itself, each control is an object that has properties, methods and events. •You can type text directly on a Web Form at the cursor location or insert XHTML elements using menu commands. Editing & adding controls to the aspx file
  • 10. Renaming the ASPX File  Right click the ASPX file in the Solution Explorer and select Rename.  Enter the new file name WebTime.aspx and press Enter. Both the ASPX file and the code-behind file are updated. Renaming the Class in the Code-Behind File and Updating the ASPX File Visual Studio’s refactoring tool, automatically updates the existing references to this class in the rest of the project to reflect this change. Check the ‚code file‛ attribute in the page directive in the .aspx file for correctness (it should have the new file name) Editing & adding controls to the aspx file
  • 11. Visual Studio generates the markup shown when you create the GUI. 11 1 <%-- WebTime.aspx --%> 2 <%-- A page that displays the current time in a Label. --%> 3 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebTime.aspx.cs" 4 Inherits="WebTime" EnableSessionState="False" %> 5 6 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 7 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 8 9 <html xmlns="http://www.w3.org/1999/xhtml"> 10 <head runat="server"> 11 <title>A Simple Web Form Example</title> 12 </head> 13 <body> 14 <form id="form1" runat="server"> 15 <div> 16 <h2>Current time on the web server:</h2> ASP.NET comments begin with <%-- and terminate with --%>, and can span multiple lines. The Page directive specifies information needed by ASP.NET to process this file. ASPX file that displays the web server’s time. The document type declaration, which specifies the document element name and the PUBLIC URI for the DTD that defines the XHTML vocabulary. XHTML documents have the root element html and markup information about the document in the head element. The body contains the main content that the browser displays. The form that contains our XHTML text and controls is set to execute on the server, which generates equivalent XHTML.
  • 12. Visual Studio generates the markup shown when you create the GUI. 17 <p> 18 <asp:Label ID="timeLabel" runat="server" BackColor="Black" 19 Font-Size="XX-Large" ForeColor="Yellow" 20 EnableViewState="False"></asp:Label> 21 </p> 22 </div> 23 </form> 24 </body> 25 </html> Markup for a label web control.The asp: tag prefix indicates that the label is an ASP.NET web control, not an XHTML element. • In an ASPX file a directive is delimited by <%@ and %>.
  • 13. Examining the aspx file • The Page directive’s Language attribute specifies the code-behind file’s language. • The CodeFile attribute specifies the code-behind filename. • When AutoEventWireup is true, ASP.NET automatically treats a method of name Page_eventName as an event handler. • When AutoEvent-Wireup is set to false, you specify event handlers using attributes in the Page directive just as you would any other web control. • The Inherits attribute (line 4) specifies the class in the code-behind file from which this ASP.NET class inherits.
  • 14. Examining the aspx file • Setting the runat attribute to "server" indicates that ASP.NET processes the element and its nested elements and generates the corresponding XHTML. • The body contains the main content that the browser displays. • The form that contains our XHTML text and controls is set to execute on the server, which generates equivalent XHTML. • The ID attribute assigns a name to a control, used as an identifier in the code-behind file. • The asp: tag prefix indicates that the label is an ASP.NET web control, not an XHTML element. • Each web control maps to a corresponding XHTML element or group of elements.
  • 15. The code-behind file (WebTime.aspx.cs) 1 // WebTime.aspx.cs 2 // Code-behind file for a page that displays the current time. 3 using System; 4 5 public partial class WebTime : System.Web.UI.Page 6 { 7 // initializes the contents of the page 8 protected void Page_Init( object sender, EventArgs e ) 9 { 10 // display the server's current time in timeLabel 11 timeLabel.Text = DateTime.Now.ToString( "hh:mm:ss" ); 12 } // end method Page_Init 13 } // end class WebTime Code-behind file for a page that displays the web server’s time. (Part 1 of 2.) The Page_Init method handles the page’s Init event, which indicates that the page is ready to be initialized. Retrieve the current time and formats it as hh:mm:ss.
  • 16. WebTime.aspx Example run • The Page_Init method handles the page’s Init event, which indicates that the page is ready to be initialized.
  • 17. Relationship Between an ASPX File and a Code Behind File • The code-behind file inherits from Page, which defines the general functionality of a web page. • The code-behind file contains a partial class. • The first time the web page is requested, this class is compiled, and an instance is created. • This instance represents our page—it creates the XHTML that is sent to the client.
  • 18. How the Code in an ASP.NET Web Page Executes When an instance of the page is created, the PreInit event occurs first, invoking method Page_PreInit, which can be used to set a page’s theme. The Init event occurs next, invoking method Page_Init, which is used to initialize objects and other aspects of the page. Next, the Load event occurs, and the Page_Load event handler executes.  The Init event is raised only once (when the page is first requested).  The Load event is raised with every request.  The page then processes any events that are generated by the page’s controls.  Once a response has been generated and sent, an Unload event occurs, which calls Page_Unload, which typically releases resources used by the page.
  • 19. How HTML is rendered by asp.net • To view the XHTML generated by ASP.NET, select View Source option in the browser • Nonvisual form components, called hidden inputs, store data that the user doesn’t need to see. • Attribute method of the form element specifies the request method (usually get or post). The action attribute identifies the resource that will be requested when a form is submitted.
  • 20. XHTML generated by ASP.NET when a web browser requests WebTime.aspx. 1 <!-- WebTime.html --> 2 <!-- The XHTML generated when WebTime.aspx is loaded. --> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 4 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 5 6 <html xmlns="http://www.w3.org/1999/xhtml"> 7 <head> 8 <title>A Simple Web Form Example</title> 9 </head> 10 <body> 11 <form method="post" action="WebTime.aspx" id="form1"> 12 <div> 13 <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value= 14 "/wEPDwUJODExMDE5NzY5ZGQ4n4mht8D7Eqxn73tM5LDnstPlCg==" /> 15 </div> Nonvisual form components, called hidden inputs, store data that the user doesn’t need to see. Attribute method of the form element specifies the request method (usually get or post). The action attribute identifies the resource that will be requested when a form is submitted.
  • 21. XHTML generated by ASP.NET when a web browser requests WebTime.aspx. 16 17 <div> 18 <h2>Current time on the web server:</h2> 19 <p> 20 <span id="timeLabel" style="color:Yellow; 21 background-color:Black;font-size:XX-Large;"> 22 03:11:49 23 </span> 24 </p> 25 </div> 26 </form> 27 </body> 28 </html> The form contains a span element to represent the text in the label. Formatting properties of time Label are converted into the style attribute of the span element.
  • 22. Running the program • You can view the Web Form several ways. – You can select Debug > Start Without Debugging, which runs the application by opening it in a browser window. – To debug your application, you can select Debug > Start Debugging. You cannot debug a web application unless debugging is explicitly enabled by the web.config file. – To view a specific ASPX file, you can right click either the Web Forms Designer or the ASPX file name and select View In Browser. – Finally, you can run your application by opening a browser window and typing the web page’s URL in the Address field.
  • 23. Event handling • GUIs are event driven. • When the user interacts with a GUI component, a corresponding event is raised (eg. Click of a button) • A method that performs a task in response to an event is called an event handler.
  • 24. Event handling example • Let’s create another ASP.NET page using Visual Studio 1. Add a Button and a Label control (label id = labelHello) 2. To create this click event handler, double click the Button on the Form. 3. The following empty event handler is declared: 4. Set the Text property of the Label control with the current time in this function. protected void Button1_Click(object sender, EventArgs e) { labelHello.Text = "Hello World! Time is " + DateTime.Now; } ‘Where Button1 is the unique id of the element
  • 25. Event handling example • To add an event handler, alternatively in markup (aspx) file: 1. Add a onclick="BClick" property to the Button control. 2. Add a function BClick to the page class in the code behind.
  • 26. Event handling • By convention, C# names the event-handler method as objectName_eventName (e.g., Button1_Click). • Each event handler receives two parameters when it is called: – An object reference named sender—a reference to the object that generated the event. – A reference to an object of type EventArgs, which contains additional information about the event. • Typically, controls can generate many different types of events. • Clicking the Events icon (the lightning-bolt icon) in the Properties window, displays all the events for the selected control.
  • 28. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 29. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com