SlideShare a Scribd company logo
Introduction to Web Programming
using ASP.NET
About the Course
Objective
Introduction to web programming using the Microsoft®
ASP.NET technology and Microsoft® IIS (Internet
Information Server).
Prerequisite
The programming language will be C#, the participants
are expected to have taken the IT519 or IT528 course
Lectures
Saturday 13:00 – 16:00 at Main Campus FENS G032
Grading
Final Exam (40% ): Last (7th
) week of the course, Saturday
Homework (60% total): 4 homework will be assigned
and they are of different weight depending on their
complexity
Outline of the Course
Introduction to web programming and ASP.NET
Create web application using Visual Studio® 2010 and C#
Create and add code-behind file to an ASP.NET web form
Examine common ASP.NET Controls
Connecting to a Database in an ASP.NET application and
ASP.NET Data Controls
Session management
Validation controls
Master pages
Configuring and deploying an ASP.NET web application on
an IIS server
Securing an ASP.NET web application
Introduction to ASP.NET AJAX
Introduction to WCF (Windows Communication
Foundation)
Internet Technologies
WWW Architecture
Web Server
Client
Server
Request:
http://www.msn.com/default.html
Response:
<html>…</html>
Network
HTTP
TCP/IP
PC/Mac/Unix
+ Browser (IE, FireFox)
Web Technologies
HTTP / HTTPS (URL, GET/POST)
Client-side:
HTML / XHTML (Extensible HyperText Markup Language)
JavaScript / VBScript (client-side scripting)
Applets / ActiveX controls
Server-side:
PHP
Phython
JSP (Java Server Pages)
ASP (Active Server Pages)
ASP.NET (next generation of ASP)
ASP Architecture
IIS
(Internet Information Server)
Client
Server
Request:
http://www.msn.com/default.aspx
Response:
<html>…</html>
Network
HTTP
TCP/IP
PC/Mac/Unix
+ Browser (IE, FireFox)
Server-Side Code
What is server-side code?
Software that runs on the
server, not the client
Receives input from
URL parameters
HTML form data
Can access server-side
databases, e-mail servers,
files, mainframes, etc.
Dynamically builds a
custom HTML response
for a client
HTTP request
(form data,
HTTP
header data)
HTTP response
HTML, XML
ASP page
(static HTML,
server-side
logic)
ASP.NET Overview and 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
Web Forms are designed to make building
web-based applications as easy as building Visual Basic
applications
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
Caching, Debugging, Extensibility
WebTime.aspx Example
Creating an ASP.NET Web Application using Visual Studio
Step 1: Creating the Web Application Project
Select File > New Web Site... and choose ASP.NET Empty Web Site
in the Templates pane.
Select File System from the drop-down list closest to Location.
Set the Language to Visual C#, and click OK.
WebTime.aspx Example
Add n 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.
The View Designer button opens the Web Form in Design
mode.
The Copy Web Site button allows you to copy the project’s
files to another location, such as a remote web server.
Finally, the ASP.NET Configuration button takes you
to the Web Site Administration Tool.
Look at Toolbox displayed in the IDE when the project loads.
Standard and Data list of web controls.
Editing the WebTime.aspx
When the project loads for the first time, the Web Forms
Designer displays the autogenerated 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.
WebTime.aspx Example
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 WebTime.aspx.cs file and add Page_Init
function to set Text property of the Label control
WebTime.aspx Example
Changing the Title of the Page
 We change the page’s title from the default Untitled Page to A Simple Web
Form Example.
 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.
Renaming the WebTime.aspx
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, which automatically
updates the existing references to this class in the rest of
the project to reflect this change.
 Right click the class name in the partial class’s
declaration and select Refactor > Rename… to open the
Rename dialog.
15
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>
WebTime.aspx ( 1 of 2 )
Visual Studio generates the markup shown when
you create the GUI.
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.
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>
WebTime.aspx
( 2 of 2 )
ASPX file that displays the web server’s time. (Part 2 of 2. )
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 %>.
WebTime.aspx Example
Examining an 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.
WebTime.aspx Example
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.
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.
WebTime.aspx Example
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.
WebTime.aspx Example
The asp:Label control is written as an XHTML span
element.
A span element contains text with formatting styles.
This control is processed on the server so that the
server can translate the control into XHTML.
If this is not supported, the asp:Label element is
written as text to the client.
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
The code-behind file (WebTime.aspx.cs)
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.
• The Page_Init method handles the page’s Init event,
which indicates that the page is ready to be initialized.
WebTime.aspx Example Run
WebTime.aspx Example
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.
ASP.NET generates another partial class that defines the
remainder of that class, based on the markup in the ASPX file.
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.
Once an instance of the web page has been created, multiple
clients can use it to access the page—no recompilation is
necessary.
WebTime.aspx Example
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.
WebTime.aspx Example
To view the XHTML generated by ASP.NET, select View
Source from the Page menu ) in Internet Explorer
(or View > Page Source if you are using Firefox).
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.
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>
WebTime.html
( 1 of 2 )
• Figure shows the XHTML generated by ASP.NET when
a web browser requests WebTime.aspx.
Fig. | XHTML response when the browser requests
WebTime.aspx. (Part 1 of 2. )
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.
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>
WebTime.html
( 2 of 2 )
Fig. | XHTML response when the browser requests
WebTime.aspx. (Part 2 of 2. )
The form contains a
span element to
represent the text in
the label. Formatting
properties of
timeLabel are
converted into the
style attribute of
the span element.
WebTime.aspx Example
When the form is processed on the server, the runat
attribute is removed.
Only those elements marked in the ASPX file with
runat="server" are modified or replaced in the
generated XHTML.
WebTime.aspx Example
The positions of controls and other elements are relative to
the Web Form’s upper-left corner. This type of layout is
known as relative positioning.
An alternate type of layout is known as absolute positioning,
in which controls are located exactly where they are dropped
on the Web Form.
You can enable absolute positioning in Design mode in the
HTML Designer > CSS Styling node of the Options dialog.
Absolute positioning is discouraged, because pages designed
in this manner may not render correctly in different
browsers or on computers with different screen resolutions
and font sizes.
Running WebTime.aspx Example
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, the
event drives the program to perform a task.
A method that performs a task in response to an event is
called an event handler.
Let’s create another ASP.NET page using Visual Studio
1. Add a Button and a Label control
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)
{
}
Event Handling Example (HelloWorld)
Event Handling Example (HelloWorld)
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.
HelloWorld Example
<%-- Hello World page that also displays the current time. --%>
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="HelloWorld.aspx.cs" Inherits="HelloWorldPage" %>
<!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>Hello World Web Form</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="buttonClick" runat="server" Font-Size="Medium"
Width="102px“ Text="Click Me" onclick="BClick" />
<br />
<asp:Label ID="labelHello" runat="server"></asp:Label>
</form>
</body> </html>
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.
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.
Markup for label &
button web controls.
The asp: tag prefix indicates that the label is an
ASP.NET web control, not an XHTML element.
ASPX Code Behind File
public partial class HelloWorldPage :
System.Web.UI.Page
{
protected void BClick(object sender, EventArgs e)
{
labelHello.Text = "Hello World! Time is " +
DateTime.Now;
}
}
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.
Other Ways to Create Event
Handlers
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.
38
Locating Event Information
To learn about the events raised by a control, select Help >
Index.
In the window, select Web Development (.NET) in the
Filtered by drop-down list and enter the name of the control’s
class in the Index window.
Programming Model
Controls and Events
Button
List
Label
Browser ASP.NET
Button code
...
List code
...
Label code
...
Event handlers
ASP.NET Architecture
Common Language Specification
Common Language Runtime
VB C++ C#
ASP.NET: Web Services
and Web Forms
JScript …
Windows
Forms
Base Classes
ADO.NET: Data and XML
VisualStudio.NET
Programming Model
ASP.NET Object Model
Controls are objects, available in
server-side code
Derived from System.Web.UI.Control
The web page is an object too
Derived from System.Web.UI.Page
User code executes on the web server in
page or control event handlers
Resources
http://msdn.microsoft.com/en-us/aa336522.aspx
http://www.asp.net/
http://www.aspfree.com/
http://www.devx.com/dotnet/

More Related Content

What's hot

ASP.NET 06 - Customizing Your Sites Appearance
ASP.NET 06 - Customizing Your Sites AppearanceASP.NET 06 - Customizing Your Sites Appearance
ASP.NET 06 - Customizing Your Sites Appearance
Randy Connolly
 
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
Jignesh Aakoliya
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
Vivek chan
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentalsGopal Ji Singh
 
Oracle application express
Oracle application expressOracle application express
Oracle application express
Abhinaw Kumar
 
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl....net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
Nancy Thomas
 
Chapter 1 (asp.net over view)
Chapter 1 (asp.net over view)Chapter 1 (asp.net over view)
Chapter 1 (asp.net over view)
let's go to study
 
SharePoint 2010 For Developers
SharePoint 2010 For DevelopersSharePoint 2010 For Developers
SharePoint 2010 For Developers
Sparked
 
Flex_rest_optimization
Flex_rest_optimizationFlex_rest_optimization
Flex_rest_optimization
Khou Suylong
 
Apex basics-for Beginners
Apex basics-for BeginnersApex basics-for Beginners
Apex basics-for Beginnershrakhra
 
Rutgers - FrontPage 98 (Advanced)
Rutgers - FrontPage 98 (Advanced)Rutgers - FrontPage 98 (Advanced)
Rutgers - FrontPage 98 (Advanced)Michael Dobe, Ph.D.
 
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
 
Asp.Net Page Life
Asp.Net Page LifeAsp.Net Page Life
Asp.Net Page Lifeguest812990
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical listdesaipratu10
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controlsRaed Aldahdooh
 
New Features of ASP.NET 4.0
New Features of ASP.NET 4.0New Features of ASP.NET 4.0
New Features of ASP.NET 4.0Buu Nguyen
 
Exploring Adobe Flex
Exploring Adobe Flex Exploring Adobe Flex
Exploring Adobe Flex
senthil0809
 

What's hot (19)

ASP.NET 06 - Customizing Your Sites Appearance
ASP.NET 06 - Customizing Your Sites AppearanceASP.NET 06 - Customizing Your Sites Appearance
ASP.NET 06 - Customizing Your Sites Appearance
 
Tutorial asp.net
Tutorial  asp.netTutorial  asp.net
Tutorial asp.net
 
Chapter 09
Chapter 09Chapter 09
Chapter 09
 
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
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
 
Oracle application express
Oracle application expressOracle application express
Oracle application express
 
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl....net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
 
Chapter 1 (asp.net over view)
Chapter 1 (asp.net over view)Chapter 1 (asp.net over view)
Chapter 1 (asp.net over view)
 
SharePoint 2010 For Developers
SharePoint 2010 For DevelopersSharePoint 2010 For Developers
SharePoint 2010 For Developers
 
Flex_rest_optimization
Flex_rest_optimizationFlex_rest_optimization
Flex_rest_optimization
 
Apex basics-for Beginners
Apex basics-for BeginnersApex basics-for Beginners
Apex basics-for Beginners
 
Rutgers - FrontPage 98 (Advanced)
Rutgers - FrontPage 98 (Advanced)Rutgers - FrontPage 98 (Advanced)
Rutgers - FrontPage 98 (Advanced)
 
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)
 
Asp.Net Page Life
Asp.Net Page LifeAsp.Net Page Life
Asp.Net Page Life
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
New Features of ASP.NET 4.0
New Features of ASP.NET 4.0New Features of ASP.NET 4.0
New Features of ASP.NET 4.0
 
Exploring Adobe Flex
Exploring Adobe Flex Exploring Adobe Flex
Exploring Adobe Flex
 

Similar to Creating web form

Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
imdurgesh
 
Asp.net architecture
Asp.net architectureAsp.net architecture
Asp.net architectureIblesoft
 
SharePoint 2007 Presentation
SharePoint 2007 PresentationSharePoint 2007 Presentation
SharePoint 2007 PresentationAjay Jain
 
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
SAMIR BHOGAYTA
 
Active server pages
Active server pagesActive server pages
Active server pages
mcatahir947
 
Programming web application
Programming web applicationProgramming web application
Programming web applicationaspnet123
 
Asp.Net 2.0 Presentation
Asp.Net 2.0 PresentationAsp.Net 2.0 Presentation
Asp.Net 2.0 Presentationsasidhar
 
C# Unit5 Notes
C# Unit5 NotesC# Unit5 Notes
C# Unit5 Notes
Sudarshan Dhondaley
 
Aspnet architecture
Aspnet architectureAspnet architecture
Aspnet architecturephantrithuc
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20
HUST
 
Wss Object Model
Wss Object ModelWss Object Model
Wss Object Modelmaddinapudi
 
Asp.net
Asp.netAsp.net
Asp.net
vijilakshmi51
 
How to develop asp web applications
How to develop asp web applicationsHow to develop asp web applications
How to develop asp web applicationsDeepankar Pathak
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetAdil Mughal
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
shan km
 

Similar to Creating web form (20)

Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
 
Asp.net architecture
Asp.net architectureAsp.net architecture
Asp.net architecture
 
SharePoint 2007 Presentation
SharePoint 2007 PresentationSharePoint 2007 Presentation
SharePoint 2007 Presentation
 
Lecture2
Lecture2Lecture2
Lecture2
 
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
 
Active server pages
Active server pagesActive server pages
Active server pages
 
Programming web application
Programming web applicationProgramming web application
Programming web application
 
As pnet
As pnetAs pnet
As pnet
 
Asp dot net long
Asp dot net longAsp dot net long
Asp dot net long
 
Asp.Net 2.0 Presentation
Asp.Net 2.0 PresentationAsp.Net 2.0 Presentation
Asp.Net 2.0 Presentation
 
Asp.net
Asp.netAsp.net
Asp.net
 
C# Unit5 Notes
C# Unit5 NotesC# Unit5 Notes
C# Unit5 Notes
 
Aspnet architecture
Aspnet architectureAspnet architecture
Aspnet architecture
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20
 
Wss Object Model
Wss Object ModelWss Object Model
Wss Object Model
 
Asp.net
Asp.netAsp.net
Asp.net
 
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 w3schools
Asp.net w3schoolsAsp.net w3schools
Asp.net w3schools
 
DevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp NetDevNext - Web Programming Concepts Using Asp Net
DevNext - Web Programming Concepts Using Asp Net
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
 

More from mentorrbuddy

Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
mentorrbuddy
 
Introduction to software project management for windows
Introduction to software project management for windowsIntroduction to software project management for windows
Introduction to software project management for windows
mentorrbuddy
 
Chap14 ado.net
Chap14 ado.netChap14 ado.net
Chap14 ado.net
mentorrbuddy
 
Chapter1 introduction to asp.net
Chapter1  introduction to asp.netChapter1  introduction to asp.net
Chapter1 introduction to asp.net
mentorrbuddy
 
Creating web form
Creating web formCreating web form
Creating web form
mentorrbuddy
 
Graphical user interface of web form
Graphical user interface of web formGraphical user interface of web form
Graphical user interface of web form
mentorrbuddy
 
Sad 07 drawing dfd supp
Sad 07 drawing dfd suppSad 07 drawing dfd supp
Sad 07 drawing dfd supp
mentorrbuddy
 
Project scope
Project scopeProject scope
Project scope
mentorrbuddy
 
Introduction to software project management (1)
Introduction to software project management (1)Introduction to software project management (1)
Introduction to software project management (1)
mentorrbuddy
 

More from mentorrbuddy (10)

Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
 
Introduction to software project management for windows
Introduction to software project management for windowsIntroduction to software project management for windows
Introduction to software project management for windows
 
Chap14 ado.net
Chap14 ado.netChap14 ado.net
Chap14 ado.net
 
Chapter1 introduction to asp.net
Chapter1  introduction to asp.netChapter1  introduction to asp.net
Chapter1 introduction to asp.net
 
Creating web form
Creating web formCreating web form
Creating web form
 
Graphical user interface of web form
Graphical user interface of web formGraphical user interface of web form
Graphical user interface of web form
 
Sad 07 drawing dfd supp
Sad 07 drawing dfd suppSad 07 drawing dfd supp
Sad 07 drawing dfd supp
 
Er
ErEr
Er
 
Project scope
Project scopeProject scope
Project scope
 
Introduction to software project management (1)
Introduction to software project management (1)Introduction to software project management (1)
Introduction to software project management (1)
 

Recently uploaded

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 

Recently uploaded (20)

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 

Creating web form

  • 1. Introduction to Web Programming using ASP.NET
  • 2. About the Course Objective Introduction to web programming using the Microsoft® ASP.NET technology and Microsoft® IIS (Internet Information Server). Prerequisite The programming language will be C#, the participants are expected to have taken the IT519 or IT528 course Lectures Saturday 13:00 – 16:00 at Main Campus FENS G032 Grading Final Exam (40% ): Last (7th ) week of the course, Saturday Homework (60% total): 4 homework will be assigned and they are of different weight depending on their complexity
  • 3. Outline of the Course Introduction to web programming and ASP.NET Create web application using Visual Studio® 2010 and C# Create and add code-behind file to an ASP.NET web form Examine common ASP.NET Controls Connecting to a Database in an ASP.NET application and ASP.NET Data Controls Session management Validation controls Master pages Configuring and deploying an ASP.NET web application on an IIS server Securing an ASP.NET web application Introduction to ASP.NET AJAX Introduction to WCF (Windows Communication Foundation)
  • 4. Internet Technologies WWW Architecture Web Server Client Server Request: http://www.msn.com/default.html Response: <html>…</html> Network HTTP TCP/IP PC/Mac/Unix + Browser (IE, FireFox)
  • 5. Web Technologies HTTP / HTTPS (URL, GET/POST) Client-side: HTML / XHTML (Extensible HyperText Markup Language) JavaScript / VBScript (client-side scripting) Applets / ActiveX controls Server-side: PHP Phython JSP (Java Server Pages) ASP (Active Server Pages) ASP.NET (next generation of ASP)
  • 6. ASP Architecture IIS (Internet Information Server) Client Server Request: http://www.msn.com/default.aspx Response: <html>…</html> Network HTTP TCP/IP PC/Mac/Unix + Browser (IE, FireFox)
  • 7. Server-Side Code What is server-side code? Software that runs on the server, not the client Receives input from URL parameters HTML form data Can access server-side databases, e-mail servers, files, mainframes, etc. Dynamically builds a custom HTML response for a client HTTP request (form data, HTTP header data) HTTP response HTML, XML ASP page (static HTML, server-side logic)
  • 8. ASP.NET Overview and 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 Web Forms are designed to make building web-based applications as easy as building Visual Basic applications 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 Caching, Debugging, Extensibility
  • 9. WebTime.aspx Example Creating an ASP.NET Web Application using Visual Studio Step 1: Creating the Web Application Project Select File > New Web Site... and choose ASP.NET Empty Web Site in the Templates pane. Select File System from the drop-down list closest to Location. Set the Language to Visual C#, and click OK.
  • 10. WebTime.aspx Example Add n 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. The View Designer button opens the Web Form in Design mode. The Copy Web Site button allows you to copy the project’s files to another location, such as a remote web server. Finally, the ASP.NET Configuration button takes you to the Web Site Administration Tool. Look at Toolbox displayed in the IDE when the project loads. Standard and Data list of web controls.
  • 11. Editing the WebTime.aspx When the project loads for the first time, the Web Forms Designer displays the autogenerated 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.
  • 12. WebTime.aspx Example 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 WebTime.aspx.cs file and add Page_Init function to set Text property of the Label control
  • 13. WebTime.aspx Example Changing the Title of the Page  We change the page’s title from the default Untitled Page to A Simple Web Form Example.  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.
  • 14. Renaming the WebTime.aspx 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, which automatically updates the existing references to this class in the rest of the project to reflect this change.  Right click the class name in the partial class’s declaration and select Refactor > Rename… to open the Rename dialog.
  • 15. 15 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> WebTime.aspx ( 1 of 2 ) Visual Studio generates the markup shown when you create the GUI. 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.
  • 16. 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> WebTime.aspx ( 2 of 2 ) ASPX file that displays the web server’s time. (Part 2 of 2. ) 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 %>.
  • 17. WebTime.aspx Example Examining an 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.
  • 18. WebTime.aspx Example 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. 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.
  • 19. WebTime.aspx Example 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.
  • 20. WebTime.aspx Example The asp:Label control is written as an XHTML span element. A span element contains text with formatting styles. This control is processed on the server so that the server can translate the control into XHTML. If this is not supported, the asp:Label element is written as text to the client.
  • 21. 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 The code-behind file (WebTime.aspx.cs) 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.
  • 22. • The Page_Init method handles the page’s Init event, which indicates that the page is ready to be initialized. WebTime.aspx Example Run
  • 23. WebTime.aspx Example 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. ASP.NET generates another partial class that defines the remainder of that class, based on the markup in the ASPX file. 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. Once an instance of the web page has been created, multiple clients can use it to access the page—no recompilation is necessary.
  • 24. WebTime.aspx Example 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.
  • 25. WebTime.aspx Example To view the XHTML generated by ASP.NET, select View Source from the Page menu ) in Internet Explorer (or View > Page Source if you are using Firefox). 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.
  • 26. 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> WebTime.html ( 1 of 2 ) • Figure shows the XHTML generated by ASP.NET when a web browser requests WebTime.aspx. Fig. | XHTML response when the browser requests WebTime.aspx. (Part 1 of 2. ) 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.
  • 27. 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> WebTime.html ( 2 of 2 ) Fig. | XHTML response when the browser requests WebTime.aspx. (Part 2 of 2. ) The form contains a span element to represent the text in the label. Formatting properties of timeLabel are converted into the style attribute of the span element.
  • 28. WebTime.aspx Example When the form is processed on the server, the runat attribute is removed. Only those elements marked in the ASPX file with runat="server" are modified or replaced in the generated XHTML.
  • 29. WebTime.aspx Example The positions of controls and other elements are relative to the Web Form’s upper-left corner. This type of layout is known as relative positioning. An alternate type of layout is known as absolute positioning, in which controls are located exactly where they are dropped on the Web Form. You can enable absolute positioning in Design mode in the HTML Designer > CSS Styling node of the Options dialog. Absolute positioning is discouraged, because pages designed in this manner may not render correctly in different browsers or on computers with different screen resolutions and font sizes.
  • 30. Running WebTime.aspx Example 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.
  • 31. Event Handling GUIs are event driven. When the user interacts with a GUI component, the event drives the program to perform a task. A method that performs a task in response to an event is called an event handler.
  • 32. Let’s create another ASP.NET page using Visual Studio 1. Add a Button and a Label control 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) { } Event Handling Example (HelloWorld)
  • 33. Event Handling Example (HelloWorld) 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.
  • 34. HelloWorld Example <%-- Hello World page that also displays the current time. --%> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloWorld.aspx.cs" Inherits="HelloWorldPage" %> <!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>Hello World Web Form</title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="buttonClick" runat="server" Font-Size="Medium" Width="102px“ Text="Click Me" onclick="BClick" /> <br /> <asp:Label ID="labelHello" runat="server"></asp:Label> </form> </body> </html> 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. 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. Markup for label & button web controls. The asp: tag prefix indicates that the label is an ASP.NET web control, not an XHTML element.
  • 35. ASPX Code Behind File public partial class HelloWorldPage : System.Web.UI.Page { protected void BClick(object sender, EventArgs e) { labelHello.Text = "Hello World! Time is " + DateTime.Now; } }
  • 36. 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.
  • 37. Other Ways to Create Event Handlers 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.
  • 38. 38 Locating Event Information To learn about the events raised by a control, select Help > Index. In the window, select Web Development (.NET) in the Filtered by drop-down list and enter the name of the control’s class in the Index window.
  • 39. Programming Model Controls and Events Button List Label Browser ASP.NET Button code ... List code ... Label code ... Event handlers
  • 40. ASP.NET Architecture Common Language Specification Common Language Runtime VB C++ C# ASP.NET: Web Services and Web Forms JScript … Windows Forms Base Classes ADO.NET: Data and XML VisualStudio.NET
  • 41. Programming Model ASP.NET Object Model Controls are objects, available in server-side code Derived from System.Web.UI.Control The web page is an object too Derived from System.Web.UI.Page User code executes on the web server in page or control event handlers

Editor's Notes

  1. 1- Generate the page using the ToolBox in Design mode: add a button and a label 2- Then show aspx markup, run the page 3- Add onClick event using the Design mode and show events 4- Explain code behind file default.aspx.cs: class derives from System.Web.UI.Page 5- set labelHello.Text = “Hello World!” 6- then set labelHello.Text = “Hello World! Time is %s” + DateTime.Now
  2. 1- Generate the page using the ToolBox in Design mode: add a button and a label 2- Then show aspx markup, run the page 3- Add onClick event using the Design mode and show events 4- Explain code behind file default.aspx.cs: class derives from System.Web.UI.Page 5- set labelHello.Text = “Hello World!” 6- then set labelHello.Text = “Hello World! Time is %s” + DateTime.Now
  3. 1- Generate the page using the ToolBox in Design mode: add a button and a label 2- Then show aspx markup, run the page 3- Add onClick event using the Design mode and show events 4- Explain code behind file default.aspx.cs: class derives from System.Web.UI.Page 5- set labelHello.Text = “Hello World!” 6- then set labelHello.Text = “Hello World! Time is %s” +
  4. ASP.NET is built upon .NET Framework Internet Information Server (IIS)