SlideShare a Scribd company logo
Introduction to
ASP.NET
development
http://www.techsyam.word
press.com
ASP.NET Overview
Key Features
 Web Forms
 Web Services
 Built on .NET Framework
 Simple programming
model
 Maintains page state
 Multibrowser support
 XCOPY deployment
 XML configuration
 Complete object model
 Session management
 Caching
 Debugging
 Extensibility
 Separation of code and UI
 Security
 ASPX, ASP side by side
 Simplified form validation
 Cookieless sessions
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
ASP.NET Overview
Architecture
Introductionto asp net-ppt
Introductionto asp net-ppt
Asp.NET ?
 Simply Server side language
 Simplified page development model
 Modular, well-factored, extensible architecture
 Superior debugging and tracing support
 Compiled, not interpreted
 Rich caching support
 Web farm scalable session state
 Automatically detects and recovers from errors
Request And Respond
ASP.NET Execution Model
 First call to particular page
General Things to know
 Client Side Scripting
 Server Side Scripting
 HTML
 JavaScript
 CSS
 Jquery
 Ajax
 XML
Background
ASP Successes
 Simple procedural programming model
 Access to COM components
 ActiveX Data Objects (ADO)
 File System Object
 Custom components
 Script-based: no compiling, just edit, save &
run
 VBScript, JScript – leverages existing skills
 Support for multiple scripting languages
 ASP has been very popular
Introductionto asp net-ppt
Introductionto asp net-ppt
Introductionto asp net-ppt
Programming Model
Controls and Events
Button
List
Text
Browser ASP.NET
Button code
...
List code
...
Text code
...
Event handlers
Web Forms in .NET
 Separate Code & Design
 Rich Web Forms
 Drag & Drop Design
 Like WinForms
Understand the Web Form
 Page Directive
 Server side code
 Form
 Normal HTML Structure
 Server Controls
Example: Inline Code Method
17
<html>
<asp:Button id="btn" runat="server"/>
...
</html>
<script Language="c#" runat="server">
private void btn_Click(object sender,
System.EventArgs e)
{
...
}
</script>
Background
Demo: HelloWorld.asp
<html>
<head><title>HelloWorld.asp</title></head>
<body>
<form method=“post">
<input type="submit" id=button1 name=button1 value="Push Me" />
<%
if (Request.Form("button1") <> "") then
Response.Write("<p>Hello, the time is " & Now())
end if
%>
</form>
</body>
</html>
You must Know
 Post Back
 communicates back to the server
 View State
 state stored in a hidden field on the page
 transported to the client and back to the server,
 Is not stored on the server
ASP.NET States
 Session State
 allows the state of objects (serializable) to
be stored for a single session (lifetime of the
user’s browser or specific timeout)
 Application State
 allows the state of objects (serializable) to
be stored for the application across
different sessions.
Master Page
 Template to Other pages
Agenda
 Background
 ASP.NET Overview
 Programming Model
 Programming Basics
 Server Controls
 Data Binding
 Conclusion
Programming Model
Controls and Events
 Server-side programming model
 Based on controls and events
 Just like Visual Basic
 Not “data in, HTML out”
 Higher level of abstraction than ASP
 Requires less code
 More modular, readable, and
maintainable
Programming Model
Controls and Events
Button
List
Text
Browser ASP.NET
Button code
...
List code
...
Text code
...
Event handlers
Page Life Cycle
PreInit Init
Init
Complete
Preload
Load
Control
events
Load
Complete
Pre
Render
Save
State
Complete
Render Unload
Programming Model
ASP.NET Object Model
 User code executes on the web server in
page or control event handlers
 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 which is a
descendant of System.Web.UI.Control
 A page can have methods, properties, etc.
Programming Model
Postbacks
 A postback occurs when a page generates
an
HTML form whose values are posted back
to the same page
 A common technique for handling form data
 In ASP and other server-side technologies the
state of the page is lost upon postback...
 Unless you explicitly write code to maintain
state
 This is tedious, bulky and error-prone
Programming Model
Postbacks Maintain State
 By default, ASP.NET maintains the state of
all server-side controls during a postback
 Can use method="post" or
method="get"
 Server-side control objects are
automatically populated during postback
 No state stored on server
 Works with all browsers
Programming Model
Server-side Controls
 Multiple sources of controls
 Built-in
 3rd party
 User-defined
 Controls range in complexity and power:
button, text, drop down, calendar, data
grid, ad rotator, validation
 Can be populated via data binding
Programming Model
Automatic Browser Compatibility
 Controls can provide automatic browser
compatibility
 Can target UpLevel or DownLevel
browsers
 UpLevel browsers support additional
functionality, such as JavaScript and DHTML
 DownLevel browsers support HTML 3.2
Programming Model
Automatic Browser Compatibility
Button code
...
Menu code
...
Text code
...
Event handlers
Button
Menu
Text
IE 4
Button
Menu
Text
Netscape
Button
Menu
Text
IE 5.5
Button
Menu
Text
IE 6
ASP.NET
Button Control
Menu Control
Text Control
...
Programming Model
Code-behind pages
 Two styles of creating ASP.NET pages
 Controls and code in .aspx file
 Controls in .aspx file, code in code-behind page
 Supported in Visual Studio.NET
 Code-behind pages allow you to separate
the
user interface design from the code
 Allows programmers and designers to work
independently
<%@ Codebehind=“WebForm1.bas”
Inherits=WebApplication1.WebForm1” %>
Programming Model
Automatic Compilation
 Just edit the code and hit the page
 ASP.NET will automatically compile the code
into an assembly
 Compiled code is cached in the CLR
Assembly Cache
 Subsequent page hits use compiled assembly
 If the text of the page changes then the
code
is recompiled
 Works just like ASP: edit, save and run
Agenda
 Background
 ASP.NET Overview
 Programming Model
 Programming Basics
 Server Controls
 Data Binding
 Conclusion
Programming Basics
Page Syntax
 The most basic page is just static text
 Any HTML page can be renamed .aspx
 Pages may contain:
 Directives: <%@ Page Language=“VB” %>
 Server controls: <asp:Button runat=“server”>
 Code blocks: <script
runat=“server”>…</script>
 Data bind expressions: <%# %>
 Server side comments: <%-- --%>
 Render code: <%= %> and <% %>
 Use is discouraged; use <script runat=server>
with code in event handlers instead
Programming Basics
The Page Directive
 Lets you specify page-specific attributes, e.g.
 AspCompat: Compatibility with ASP
 Buffer: Controls page output buffering
 Codepage: Code page for this .aspx page
 Content Type: MIME type of the response
 ErrorPage: URL if unhandled error occurs
 Inherits: Base class of Page object
 Language: Programming language
 Trace: Enables tracing for this page
 Transaction: COM+ transaction setting
 Only one page directive per .aspx file
Programming Basics
Server Control Syntax
 Controls are declared as HTML tags with
runat=“server” attribute
 Tag identifies which type of control to create
 Control is implemented as an ASP.NET class
 The id attribute provides programmatic identifier
 It names the instance available during post back
 Just like Dynamic HTML
<input type=text id=text2 runat=“server” />
<asp:calendar id=myCal runat=“server” />
Programming Basics
Server Control Properties
 Tag attributes map to control properties
c1.Text = “Foo”
c2.Rows = 5
<asp:button id=“c1" Text="Foo" runat=“server”>
<asp:ListBox id=“c2" Rows="5" runat=“server”>
 Tags and attributes are case-insensitive
 Control properties can be set programmatically
Programming Basics
Maintaining State
 By default. controls maintain their state across
multiple post back requests
 Implemented using a hidden HTML field:
__VIEWSTATE
 Works for controls with input data (e.g. Textbox,
Checkbox), non-input controls (e.g. Label, Data
Grid), and hybrids (e.g. Dropdown List,
ListBox)
 Can be disabled per control or entire page
 Set EnableViewState=“false”
 Lets you minimize size of __VIEWSTATE
Programming Basics
Maintaining State
 Demo: MaintainingState.asp,
MaintainingState.aspx
Programming Basics
Server Code Blocks
 Server code lives in a script block marked
runat=“server”
 Script blocks can contain
 Variables, methods, event handlers, properties
 They become members of a custom Page
object
<script language="C#" runat=server>
<script language="VB" runat=server>
<script language="JScript" runat=server>
Programming Basics
Page Events
 Pages are structured using events
 Enables clean code organization
 Avoids the “Monster IF” statement
 Less complex than ASP pages
 Code can respond to page events
 e.g. Page_Load, Page_Unload
 Code can respond to control events
 Button1_Click
 Textbox1_Changed
Programming Basics
Page Event Lifecycle
Page_Load
Page_Unload
Textbox1_Changed
Button1_Click
Initialize
Restore Control State
Save Control State
Render
1. Change Events
2. Action Events
Page_Init
Control Events
Load Page
Unload Page
Programming Basics
Page Loading
 Page_Load fires at beginning of request
after controls are initialized
 Input control values already populated
protected sub Page Load(s as Object, e as EventArgs)
Message.Text = "Howdy, World!"
End sub
Programming Basics
Page Loading
 Page Load fires on every request
 Use Page.IsPostBack to execute
conditional logic
 If a Page/Control is maintaining state then
need only initialize it when IsPostBack is
falseprotected sub Page Load(s as Object, e as EventArgs)
if (Page.IsPostBack) then
else
' Executes only on initial page load
Message.Text = "initial value"
' Rest of procedure executes on every request
end sub
Programming Basics
Server Control Events
 Change Events
 By default, these execute only on next action
event
 E.g. OnTextChanged, OnCheckedChanged
 Change events fire in random order
 Action Events
 Cause an immediate postback to server
 E.g. OnClick
 Works with any browser
 No client script required, no applets,
no ActiveX® Controls!
Programming Basics
Wiring Up Control Events
 Control event handlers are identified on the tag
 Event handler code
protected sub btn1_Click(s as Object, e as EventArgs)
Message.Text = “Button1 clicked”
end sub
<asp:button onclick="btn1_click“ runat=server>
<asp:textbox onchanged="text1_changed“ runat=server>
Programming Basics
Event Arguments
 Events pass two arguments:
 The sender, declared as type object
 Usually the object representing the control that
generated
the event
 Allows you to use the same event handler for
multiple controls
 Arguments, declared as type EventArgs
 Provides additional data specific to the event
 EventArgs itself contains no data; a class
derived from EventArgs will be passed
Programming Basics
Page Unloading
 Page_Unload fires after the page is
rendered
 Don’t try to add to output
 Useful for logging and clean up
protected sub Page Unload(s as Object, e as EventArgs)
MyApp.LogPageComplete()
end sub
Programming Basics
Import Directive
 Adds code namespace reference to
page
 Avoids having to fully qualify .NET types and
class names
 Equivalent to the VB imports directive
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
Programming Basics
Page Class
 The Page object is always available when
handling server-side events
 Provides a large set of useful properties
and methods, including:
 Application, Cache, Controls,
EnableViewState, EnableViewStateMac,
ErrorPage, IsPostBack, IsValid,
Request, Response, Server, Session,
Trace, User, Validators
 DataBind(), LoadControl(), MapPath(),
Validate()
Agenda
 Background
 ASP.NET Overview
 Programming Model
 Programming Basics
 Server Controls
 Data Binding
 Conclusion
Server Controls
 ASP.NET ships with ~50 built-in controls
 Organized into logical families
 HTML controls
 Controls / properties map 1:1 with HTML
 Web controls
 Richer functionality
 More consistent object model
Server Controls
HTML Controls
 Work well with existing HTML designers
 Properties map 1:1 with HTML
table.bgcolor ="red"
 Can specify client-side event handlers
 Good when quickly converting existing pages
 Derived from
System.Web.UI.HtmlControls.HtmlControl
 Supported controls have custom class,
others derive from HtmlGenericControl
Server Controls
HTML Controls
 Supported controls
 <a>
 <img>
 <form>
 <table>
 <tr>
 <td>
 <th>
 <select>
 <textarea>
 <button>
 <input type=text>
 <input type=file>
 <input type=submit>
 <input type=button>
 <input type=reset>
 <input type=hidden>
Server Controls
HTML Controls
 Demo 1: HTMLControls1.aspx
 Basic page lifecycle with HTML Controls
 Demo 2: HTMLControls2.aspx
 More HTML Controls
Server Controls
HTML Controls
 Can use controls two ways:
 Handle everything in action events (e.g.
button click)
 Event code will read the values of other
controls (e.g. text, check boxes, radio
buttons, select lists)
 Handle change events as well as action
events
Server Controls
Web Controls
 Consistent object model
Label1.BackColor = Color.Red
Table.BackColor = Color.Blue
 Richer functionality
 E.g. AutoPostBack, additional methods
 Automatic uplevel/downlevel support
 E.g. validation controls
 Strongly-typed; no generic control
 Enables better compiler type checking
Server Controls
Web Controls
 Web controls appear in HTML markup as
namespaced tags
 Web controls have an asp: prefix
<asp:button onclick="button1_click“ runat=server>
<asp:textbox onchanged="text1_changed“ runat=server>
 Defined in the System.Web.UI.WebControls
namespace
 This namespace is automatically mapped to the
asp: prefix
Server Controls
Web Controls
 Web Controls provide extensive properties
to control display and format, e.g.
 Font
 BackColor, ForeColor
 BorderColor, BorderStyle, BorderWidth
 Style, CssClass
 Height, Width
 Visible, Enabled
Server Controls
Web Controls
 Four types of Web Controls
 Intrinsic controls
 List controls
 Rich controls
 Validation controls
Server Controls
Intrinsic Controls
 Correspond to HTML controls
 Supported controls
 <asp:button>
 <asp:imagebutton>
 <asp:linkbutton>
 <asp:hyperlink>
 <asp:textbox>
 <asp:checkbox>
 <asp:radiobutton>
 <asp:image>
 <asp:label>
 <asp:panel>
 <asp:table>
Server Controls
Intrinisic Controls
 TextBox, ListControl, CheckBox and
their subclasses don’t automatically do a
postback when their controls are
changed
 Specify AutoPostBack=true to make
change events cause a postback
Server Controls
List Controls
 Controls that handle repetition
 Supported controls
 <asp:dropdownlist>
 <asp:listbox>
 <asp:radiobuttonlist>
 <asp:checkboxlist>
 <asp:repeater>
 <asp:datalist>
 <asp:datagrid>
Server Controls
List Controls
 Repeater, DataList and DataGrid
controls
 Powerful, customizable list controls
 Expose templates for customization
 Can contain other controls
 Provide event bubbling through their
OnItemCommand event
 More about these controls and templates
later
Server Controls
Checkbox List & RadioButtonList
 Provides a collection of check box or
radio button controls
 Can be populated via data binding
<asp:CheckBoxList id=Check1 runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
</asp:CheckBoxList>
Server Controls
Intrinisic & Simple List Controls
 Demo 1: WebControls1.aspx
 Assorted intrinsic and list controls
 Demo 2: WebControls2.aspx
 Same controls with AutoPostBack
Server Controls
Rich Controls
 Custom controls with rich functionality
 Supported Controls
 <asp:calendar>
 <asp:adrotator>
 More will be added
 3rd party controls are coming
 Demo: RichControls1.aspx
Server Controls
Validation Controls
 Rich, declarative validation
 Validation declared separately from input
control
 Extensible validation framework
 Supports validation on client and server
 Automatically detects uplevel clients
 Avoids roundtrips for uplevel clients
 Server-side validation is always done
 Prevents users from spoofing Web Forms
Server Controls
Validation Controls
 <asp:RequiredFieldValidator>
 Ensures that a value is entered
 <asp:RangeValidator>
 Checks if value is within minimum and maximum values
 <asp:CompareValidator>
 Compares value against constant, another control or
data type
 <asp:RegularExpressionValidator>
 Tests if value matches a predefined pattern
 <asp:CustomValidator>
 Lets you create custom client- or server-side validation
function
 <asp:ValidationSummary>
 Displays list of validation errors in one place
Server Controls
Validation Controls
 Validation controls are derived from
System.Web.UI.WebControls.BaseValidator,
which is derived from the Label control
 Validation controls contain text which is displayed
only if validation fails
 Text property is displayed at control location
 ErrorMessage is displayed in summary
Server Controls
Validation Controls
 Validation controls are associated with
their target control using the
ControlToValidate property
 Can create multiple validation controls
with the same target control
<asp:TextBox id=TextBox1 runat=server />
<asp:RequiredFieldValidator id="Req1"
ControlToValidate="TextBox1"
Text="Required Field" runat=server />
Server Controls
Validation Controls
 Page.IsValid indicates if all validation
controls on the page succeed
void Submit_click(s as object, e as EventArgs)
if (Page.IsValid) then
Message.Text = "Page is valid!"
end if
end sub
Server Controls
Validation Controls
 Display property controls layout
 Static: fixed layout, display won’t change
if invalid
 Dynamic: dynamic layout
 None: no display; can still use Validation
Summary and Page.IsValid
 Type property specifies expected data
type: Currency, Date, Double, Integer,
String
Server Controls
Validation Controls
 Can force down-level option
 Only server-side validation
<% @ Page Language="c#"
ClientTarget="DownLevel" %>
Server Controls
Validation Controls
 Demo: ValidationControls1.aspx
 Demonstrates each type of validation
control
Agenda
 Background
 ASP.NET Overview
 Programming Model
 Programming Basics
 Server Controls
 Data Binding
 Conclusion
Data Binding
How to Populate Server Controls?
 Specify the data in the control’s tags
 Not dynamic: can’t get data from a database
 Write code that uses the control’s object
model
 This is okay if you need to populate a simple
value or list, but quickly gets too complicated
for populating sophisticated displays
 Data binding
 Create an object that holds the data
(Dataset, Array, string, int, etc.)
 Associate that object with the control
Data Binding
What Is It?
 Provides a single simple yet powerful way to
populate Web Form controls with data
 Enables clean separation of code from UI
 Supports binding to any data source
 Properties, expressions, method calls
 Collections (Array, Hashtable, etc.)
 DataSet, DataTable, DataView, DataReader
 XML
 One way snapshot model
 Requires code to reapply to data model
Data Binding
What Is It?
 Allows you to specify an expression
 When the DataBind method of the control is
called, the expression is evaluated and
bound
 DataBind for a single control (and sub controls)
 Page.DataBind binds all controls on a page
 Works for scalars, e.g. Label control
 Works for lists, e.g. DropDown control,
ListBox control, etc.
 Enables the use of templates
Data Binding
Scalar Expressions
 Data binding expression: <%#
expression %>
 Expression is evaluated when DataBind()
is called
<asp: Label id=label1
Text=<%# “The result is “ & (1 + 2) &
“, the time is “ & DateTime.Now.ToLongTimeString() %>
runat="server" />
public sub Page Load(s as object, e as EventArgs)
if (Page.IsPostBack) then
else
Page.DataBind()
end if
end sub
Data Binding
Scalar Expressions
 Demo: DataBinding1.aspx
 Data binding to simple, scalar expressions
Data Binding
Simple Lists
 Data binding a list creates a user interface
element for each item in the list
 Each item contains text (displayed to user)
and an optional value (not displayed)
 The simple list controls:
 <asp:ListBox>
 Single or multiple select
 <asp:DropDownList>
 <asp:RadioButtonList>
 <asp:CheckBoxList>
Data Binding
Simple Lists
 Steps to data bind a list control
 Declare the list control
 Optionally set DataValueField
and DataTextField
 Set its Data Source
 Call DataBind() method
Data Binding
Simple Lists
 Demo: DataBinding2.aspx
 Data binding to simple lists
Resources General Sites
 http://msdn.microsoft.com/net/aspnet/default.asp
 http://www.asp.net/
 http://www.fmexpense.com/quickstart/aspplus/defau
lt.htm
 http://www.asptoday.com/
 http://www.aspng.com/aspng/index.aspx
 http://www.4guysfromrolla.com/
 http://www.aspfree.com/
 http://www.devx.com/dotnet/
 http://www.ibuyspy.com/
Starting ASP.NET Development
 Web Site
 Don’t use this, here for compatibility only
 Each page is dynamically loaded into
memory
 Slow on first load after deployment
 No need to recompile for code change
Starting ASP.NET Development
..
 Web Application
 Recommended
 Compiles all pages into one DLL
 Faster on first load after deployment
 Must recompile whole site for code change
Web Project in Asp.net
Thank You!

More Related Content

PPT
ASP.NET 3.5 SP1 (VSLive San Francisco 2009)
PPT
Silverlight 2
PPTX
Ch3 server controls
PPTX
Overview of ASP.Net by software outsourcing company india
PPTX
Ch 04 asp.net application
PPT
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
PPT
Asp.net.
PPTX
Web forms in ASP.net
ASP.NET 3.5 SP1 (VSLive San Francisco 2009)
Silverlight 2
Ch3 server controls
Overview of ASP.Net by software outsourcing company india
Ch 04 asp.net application
.net training | learn .net | Microsoft dot net Course | Microsoft dot net onl...
Asp.net.
Web forms in ASP.net

What's hot (20)

PPT
ASP.NET 05 - Exception Handling And Validation Controls
PPTX
New Features of ASP.NET 4.0
PDF
Asp .net web form fundamentals
ZIP
ASP.Net Presentation Part1
PPT
PPT
ASP.NET 02 - How ASP.NET Works
PPT
Csphtp1 20
DOC
Tutorial asp.net
PPT
Developing a Better User Experience with "Atlas"
PPT
Atlas Php
PPTX
Asp Net Advance Topics
PDF
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
PPT
ASP.NET 03 - Working With Web Server Controls
PPT
Active server pages
PPT
Asp.net server controls
PPTX
Ajax control tool kit
PPTX
Ajax and ASP.NET AJAX
PDF
Webformer: a Rapid Application Development Toolkit for Writing Ajax Web Form ...
PPT
.Net course-in-mumbai-ppt
PPT
ASP.NET AJAX Basics
ASP.NET 05 - Exception Handling And Validation Controls
New Features of ASP.NET 4.0
Asp .net web form fundamentals
ASP.Net Presentation Part1
ASP.NET 02 - How ASP.NET Works
Csphtp1 20
Tutorial asp.net
Developing a Better User Experience with "Atlas"
Atlas Php
Asp Net Advance Topics
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
ASP.NET 03 - Working With Web Server Controls
Active server pages
Asp.net server controls
Ajax control tool kit
Ajax and ASP.NET AJAX
Webformer: a Rapid Application Development Toolkit for Writing Ajax Web Form ...
.Net course-in-mumbai-ppt
ASP.NET AJAX Basics
Ad

Similar to Introductionto asp net-ppt (20)

PPT
Intro To Asp Net And Web Forms
PPTX
ASP.NET Lecture 1
PPT
Developing an ASP.NET Web Application
PPT
How to develop asp web applications
PPTX
NET_Training.pptx
PPT
Asp.net architecture
PPTX
PPT
Asp.net basic
PPT
Asp dot net long
PPT
Intro to asp.net
PPT
Server Controls of ASP.Net
PPTX
Introduction to ASP.NET
PPT
Aspnet
PPT
ASP.NET OVERVIEW
PPT
PPTX
Introduction to asp.net
PPTX
Asp.net
PPTX
Introduction to asp.net
PPT
Introduction to ASP.net. It provides basic introduction
Intro To Asp Net And Web Forms
ASP.NET Lecture 1
Developing an ASP.NET Web Application
How to develop asp web applications
NET_Training.pptx
Asp.net architecture
Asp.net basic
Asp dot net long
Intro to asp.net
Server Controls of ASP.Net
Introduction to ASP.NET
Aspnet
ASP.NET OVERVIEW
Introduction to asp.net
Asp.net
Introduction to asp.net
Introduction to ASP.net. It provides basic introduction
Ad

Recently uploaded (20)

PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Transforming Manufacturing operations through Intelligent Integrations
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Big Data Technologies - Introduction.pptx
GamePlan Trading System Review: Professional Trader's Honest Take
Sensors and Actuators in IoT Systems using pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Understanding_Digital_Forensics_Presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
NewMind AI Weekly Chronicles - August'25 Week I
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Transforming Manufacturing operations through Intelligent Integrations
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
“AI and Expert System Decision Support & Business Intelligence Systems”
Chapter 2 Digital Image Fundamentals.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Monthly Chronicles - July 2025
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Big Data Technologies - Introduction.pptx

Introductionto asp net-ppt

  • 2. ASP.NET Overview Key Features  Web Forms  Web Services  Built on .NET Framework  Simple programming model  Maintains page state  Multibrowser support  XCOPY deployment  XML configuration  Complete object model  Session management  Caching  Debugging  Extensibility  Separation of code and UI  Security  ASPX, ASP side by side  Simplified form validation  Cookieless sessions
  • 3. 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 ASP.NET Overview Architecture
  • 6. Asp.NET ?  Simply Server side language  Simplified page development model  Modular, well-factored, extensible architecture  Superior debugging and tracing support  Compiled, not interpreted  Rich caching support  Web farm scalable session state  Automatically detects and recovers from errors
  • 8. ASP.NET Execution Model  First call to particular page
  • 9. General Things to know  Client Side Scripting  Server Side Scripting  HTML  JavaScript  CSS  Jquery  Ajax  XML
  • 10. Background ASP Successes  Simple procedural programming model  Access to COM components  ActiveX Data Objects (ADO)  File System Object  Custom components  Script-based: no compiling, just edit, save & run  VBScript, JScript – leverages existing skills  Support for multiple scripting languages  ASP has been very popular
  • 14. Programming Model Controls and Events Button List Text Browser ASP.NET Button code ... List code ... Text code ... Event handlers
  • 15. Web Forms in .NET  Separate Code & Design  Rich Web Forms  Drag & Drop Design  Like WinForms
  • 16. Understand the Web Form  Page Directive  Server side code  Form  Normal HTML Structure  Server Controls
  • 17. Example: Inline Code Method 17 <html> <asp:Button id="btn" runat="server"/> ... </html> <script Language="c#" runat="server"> private void btn_Click(object sender, System.EventArgs e) { ... } </script>
  • 18. Background Demo: HelloWorld.asp <html> <head><title>HelloWorld.asp</title></head> <body> <form method=“post"> <input type="submit" id=button1 name=button1 value="Push Me" /> <% if (Request.Form("button1") <> "") then Response.Write("<p>Hello, the time is " & Now()) end if %> </form> </body> </html>
  • 19. You must Know  Post Back  communicates back to the server  View State  state stored in a hidden field on the page  transported to the client and back to the server,  Is not stored on the server
  • 20. ASP.NET States  Session State  allows the state of objects (serializable) to be stored for a single session (lifetime of the user’s browser or specific timeout)  Application State  allows the state of objects (serializable) to be stored for the application across different sessions.
  • 21. Master Page  Template to Other pages
  • 22. Agenda  Background  ASP.NET Overview  Programming Model  Programming Basics  Server Controls  Data Binding  Conclusion
  • 23. Programming Model Controls and Events  Server-side programming model  Based on controls and events  Just like Visual Basic  Not “data in, HTML out”  Higher level of abstraction than ASP  Requires less code  More modular, readable, and maintainable
  • 24. Programming Model Controls and Events Button List Text Browser ASP.NET Button code ... List code ... Text code ... Event handlers
  • 25. Page Life Cycle PreInit Init Init Complete Preload Load Control events Load Complete Pre Render Save State Complete Render Unload
  • 26. Programming Model ASP.NET Object Model  User code executes on the web server in page or control event handlers  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 which is a descendant of System.Web.UI.Control  A page can have methods, properties, etc.
  • 27. Programming Model Postbacks  A postback occurs when a page generates an HTML form whose values are posted back to the same page  A common technique for handling form data  In ASP and other server-side technologies the state of the page is lost upon postback...  Unless you explicitly write code to maintain state  This is tedious, bulky and error-prone
  • 28. Programming Model Postbacks Maintain State  By default, ASP.NET maintains the state of all server-side controls during a postback  Can use method="post" or method="get"  Server-side control objects are automatically populated during postback  No state stored on server  Works with all browsers
  • 29. Programming Model Server-side Controls  Multiple sources of controls  Built-in  3rd party  User-defined  Controls range in complexity and power: button, text, drop down, calendar, data grid, ad rotator, validation  Can be populated via data binding
  • 30. Programming Model Automatic Browser Compatibility  Controls can provide automatic browser compatibility  Can target UpLevel or DownLevel browsers  UpLevel browsers support additional functionality, such as JavaScript and DHTML  DownLevel browsers support HTML 3.2
  • 31. Programming Model Automatic Browser Compatibility Button code ... Menu code ... Text code ... Event handlers Button Menu Text IE 4 Button Menu Text Netscape Button Menu Text IE 5.5 Button Menu Text IE 6 ASP.NET Button Control Menu Control Text Control ...
  • 32. Programming Model Code-behind pages  Two styles of creating ASP.NET pages  Controls and code in .aspx file  Controls in .aspx file, code in code-behind page  Supported in Visual Studio.NET  Code-behind pages allow you to separate the user interface design from the code  Allows programmers and designers to work independently <%@ Codebehind=“WebForm1.bas” Inherits=WebApplication1.WebForm1” %>
  • 33. Programming Model Automatic Compilation  Just edit the code and hit the page  ASP.NET will automatically compile the code into an assembly  Compiled code is cached in the CLR Assembly Cache  Subsequent page hits use compiled assembly  If the text of the page changes then the code is recompiled  Works just like ASP: edit, save and run
  • 34. Agenda  Background  ASP.NET Overview  Programming Model  Programming Basics  Server Controls  Data Binding  Conclusion
  • 35. Programming Basics Page Syntax  The most basic page is just static text  Any HTML page can be renamed .aspx  Pages may contain:  Directives: <%@ Page Language=“VB” %>  Server controls: <asp:Button runat=“server”>  Code blocks: <script runat=“server”>…</script>  Data bind expressions: <%# %>  Server side comments: <%-- --%>  Render code: <%= %> and <% %>  Use is discouraged; use <script runat=server> with code in event handlers instead
  • 36. Programming Basics The Page Directive  Lets you specify page-specific attributes, e.g.  AspCompat: Compatibility with ASP  Buffer: Controls page output buffering  Codepage: Code page for this .aspx page  Content Type: MIME type of the response  ErrorPage: URL if unhandled error occurs  Inherits: Base class of Page object  Language: Programming language  Trace: Enables tracing for this page  Transaction: COM+ transaction setting  Only one page directive per .aspx file
  • 37. Programming Basics Server Control Syntax  Controls are declared as HTML tags with runat=“server” attribute  Tag identifies which type of control to create  Control is implemented as an ASP.NET class  The id attribute provides programmatic identifier  It names the instance available during post back  Just like Dynamic HTML <input type=text id=text2 runat=“server” /> <asp:calendar id=myCal runat=“server” />
  • 38. Programming Basics Server Control Properties  Tag attributes map to control properties c1.Text = “Foo” c2.Rows = 5 <asp:button id=“c1" Text="Foo" runat=“server”> <asp:ListBox id=“c2" Rows="5" runat=“server”>  Tags and attributes are case-insensitive  Control properties can be set programmatically
  • 39. Programming Basics Maintaining State  By default. controls maintain their state across multiple post back requests  Implemented using a hidden HTML field: __VIEWSTATE  Works for controls with input data (e.g. Textbox, Checkbox), non-input controls (e.g. Label, Data Grid), and hybrids (e.g. Dropdown List, ListBox)  Can be disabled per control or entire page  Set EnableViewState=“false”  Lets you minimize size of __VIEWSTATE
  • 40. Programming Basics Maintaining State  Demo: MaintainingState.asp, MaintainingState.aspx
  • 41. Programming Basics Server Code Blocks  Server code lives in a script block marked runat=“server”  Script blocks can contain  Variables, methods, event handlers, properties  They become members of a custom Page object <script language="C#" runat=server> <script language="VB" runat=server> <script language="JScript" runat=server>
  • 42. Programming Basics Page Events  Pages are structured using events  Enables clean code organization  Avoids the “Monster IF” statement  Less complex than ASP pages  Code can respond to page events  e.g. Page_Load, Page_Unload  Code can respond to control events  Button1_Click  Textbox1_Changed
  • 43. Programming Basics Page Event Lifecycle Page_Load Page_Unload Textbox1_Changed Button1_Click Initialize Restore Control State Save Control State Render 1. Change Events 2. Action Events Page_Init Control Events Load Page Unload Page
  • 44. Programming Basics Page Loading  Page_Load fires at beginning of request after controls are initialized  Input control values already populated protected sub Page Load(s as Object, e as EventArgs) Message.Text = "Howdy, World!" End sub
  • 45. Programming Basics Page Loading  Page Load fires on every request  Use Page.IsPostBack to execute conditional logic  If a Page/Control is maintaining state then need only initialize it when IsPostBack is falseprotected sub Page Load(s as Object, e as EventArgs) if (Page.IsPostBack) then else ' Executes only on initial page load Message.Text = "initial value" ' Rest of procedure executes on every request end sub
  • 46. Programming Basics Server Control Events  Change Events  By default, these execute only on next action event  E.g. OnTextChanged, OnCheckedChanged  Change events fire in random order  Action Events  Cause an immediate postback to server  E.g. OnClick  Works with any browser  No client script required, no applets, no ActiveX® Controls!
  • 47. Programming Basics Wiring Up Control Events  Control event handlers are identified on the tag  Event handler code protected sub btn1_Click(s as Object, e as EventArgs) Message.Text = “Button1 clicked” end sub <asp:button onclick="btn1_click“ runat=server> <asp:textbox onchanged="text1_changed“ runat=server>
  • 48. Programming Basics Event Arguments  Events pass two arguments:  The sender, declared as type object  Usually the object representing the control that generated the event  Allows you to use the same event handler for multiple controls  Arguments, declared as type EventArgs  Provides additional data specific to the event  EventArgs itself contains no data; a class derived from EventArgs will be passed
  • 49. Programming Basics Page Unloading  Page_Unload fires after the page is rendered  Don’t try to add to output  Useful for logging and clean up protected sub Page Unload(s as Object, e as EventArgs) MyApp.LogPageComplete() end sub
  • 50. Programming Basics Import Directive  Adds code namespace reference to page  Avoids having to fully qualify .NET types and class names  Equivalent to the VB imports directive <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %>
  • 51. Programming Basics Page Class  The Page object is always available when handling server-side events  Provides a large set of useful properties and methods, including:  Application, Cache, Controls, EnableViewState, EnableViewStateMac, ErrorPage, IsPostBack, IsValid, Request, Response, Server, Session, Trace, User, Validators  DataBind(), LoadControl(), MapPath(), Validate()
  • 52. Agenda  Background  ASP.NET Overview  Programming Model  Programming Basics  Server Controls  Data Binding  Conclusion
  • 53. Server Controls  ASP.NET ships with ~50 built-in controls  Organized into logical families  HTML controls  Controls / properties map 1:1 with HTML  Web controls  Richer functionality  More consistent object model
  • 54. Server Controls HTML Controls  Work well with existing HTML designers  Properties map 1:1 with HTML table.bgcolor ="red"  Can specify client-side event handlers  Good when quickly converting existing pages  Derived from System.Web.UI.HtmlControls.HtmlControl  Supported controls have custom class, others derive from HtmlGenericControl
  • 55. Server Controls HTML Controls  Supported controls  <a>  <img>  <form>  <table>  <tr>  <td>  <th>  <select>  <textarea>  <button>  <input type=text>  <input type=file>  <input type=submit>  <input type=button>  <input type=reset>  <input type=hidden>
  • 56. Server Controls HTML Controls  Demo 1: HTMLControls1.aspx  Basic page lifecycle with HTML Controls  Demo 2: HTMLControls2.aspx  More HTML Controls
  • 57. Server Controls HTML Controls  Can use controls two ways:  Handle everything in action events (e.g. button click)  Event code will read the values of other controls (e.g. text, check boxes, radio buttons, select lists)  Handle change events as well as action events
  • 58. Server Controls Web Controls  Consistent object model Label1.BackColor = Color.Red Table.BackColor = Color.Blue  Richer functionality  E.g. AutoPostBack, additional methods  Automatic uplevel/downlevel support  E.g. validation controls  Strongly-typed; no generic control  Enables better compiler type checking
  • 59. Server Controls Web Controls  Web controls appear in HTML markup as namespaced tags  Web controls have an asp: prefix <asp:button onclick="button1_click“ runat=server> <asp:textbox onchanged="text1_changed“ runat=server>  Defined in the System.Web.UI.WebControls namespace  This namespace is automatically mapped to the asp: prefix
  • 60. Server Controls Web Controls  Web Controls provide extensive properties to control display and format, e.g.  Font  BackColor, ForeColor  BorderColor, BorderStyle, BorderWidth  Style, CssClass  Height, Width  Visible, Enabled
  • 61. Server Controls Web Controls  Four types of Web Controls  Intrinsic controls  List controls  Rich controls  Validation controls
  • 62. Server Controls Intrinsic Controls  Correspond to HTML controls  Supported controls  <asp:button>  <asp:imagebutton>  <asp:linkbutton>  <asp:hyperlink>  <asp:textbox>  <asp:checkbox>  <asp:radiobutton>  <asp:image>  <asp:label>  <asp:panel>  <asp:table>
  • 63. Server Controls Intrinisic Controls  TextBox, ListControl, CheckBox and their subclasses don’t automatically do a postback when their controls are changed  Specify AutoPostBack=true to make change events cause a postback
  • 64. Server Controls List Controls  Controls that handle repetition  Supported controls  <asp:dropdownlist>  <asp:listbox>  <asp:radiobuttonlist>  <asp:checkboxlist>  <asp:repeater>  <asp:datalist>  <asp:datagrid>
  • 65. Server Controls List Controls  Repeater, DataList and DataGrid controls  Powerful, customizable list controls  Expose templates for customization  Can contain other controls  Provide event bubbling through their OnItemCommand event  More about these controls and templates later
  • 66. Server Controls Checkbox List & RadioButtonList  Provides a collection of check box or radio button controls  Can be populated via data binding <asp:CheckBoxList id=Check1 runat="server"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> <asp:ListItem>Item 5</asp:ListItem> </asp:CheckBoxList>
  • 67. Server Controls Intrinisic & Simple List Controls  Demo 1: WebControls1.aspx  Assorted intrinsic and list controls  Demo 2: WebControls2.aspx  Same controls with AutoPostBack
  • 68. Server Controls Rich Controls  Custom controls with rich functionality  Supported Controls  <asp:calendar>  <asp:adrotator>  More will be added  3rd party controls are coming  Demo: RichControls1.aspx
  • 69. Server Controls Validation Controls  Rich, declarative validation  Validation declared separately from input control  Extensible validation framework  Supports validation on client and server  Automatically detects uplevel clients  Avoids roundtrips for uplevel clients  Server-side validation is always done  Prevents users from spoofing Web Forms
  • 70. Server Controls Validation Controls  <asp:RequiredFieldValidator>  Ensures that a value is entered  <asp:RangeValidator>  Checks if value is within minimum and maximum values  <asp:CompareValidator>  Compares value against constant, another control or data type  <asp:RegularExpressionValidator>  Tests if value matches a predefined pattern  <asp:CustomValidator>  Lets you create custom client- or server-side validation function  <asp:ValidationSummary>  Displays list of validation errors in one place
  • 71. Server Controls Validation Controls  Validation controls are derived from System.Web.UI.WebControls.BaseValidator, which is derived from the Label control  Validation controls contain text which is displayed only if validation fails  Text property is displayed at control location  ErrorMessage is displayed in summary
  • 72. Server Controls Validation Controls  Validation controls are associated with their target control using the ControlToValidate property  Can create multiple validation controls with the same target control <asp:TextBox id=TextBox1 runat=server /> <asp:RequiredFieldValidator id="Req1" ControlToValidate="TextBox1" Text="Required Field" runat=server />
  • 73. Server Controls Validation Controls  Page.IsValid indicates if all validation controls on the page succeed void Submit_click(s as object, e as EventArgs) if (Page.IsValid) then Message.Text = "Page is valid!" end if end sub
  • 74. Server Controls Validation Controls  Display property controls layout  Static: fixed layout, display won’t change if invalid  Dynamic: dynamic layout  None: no display; can still use Validation Summary and Page.IsValid  Type property specifies expected data type: Currency, Date, Double, Integer, String
  • 75. Server Controls Validation Controls  Can force down-level option  Only server-side validation <% @ Page Language="c#" ClientTarget="DownLevel" %>
  • 76. Server Controls Validation Controls  Demo: ValidationControls1.aspx  Demonstrates each type of validation control
  • 77. Agenda  Background  ASP.NET Overview  Programming Model  Programming Basics  Server Controls  Data Binding  Conclusion
  • 78. Data Binding How to Populate Server Controls?  Specify the data in the control’s tags  Not dynamic: can’t get data from a database  Write code that uses the control’s object model  This is okay if you need to populate a simple value or list, but quickly gets too complicated for populating sophisticated displays  Data binding  Create an object that holds the data (Dataset, Array, string, int, etc.)  Associate that object with the control
  • 79. Data Binding What Is It?  Provides a single simple yet powerful way to populate Web Form controls with data  Enables clean separation of code from UI  Supports binding to any data source  Properties, expressions, method calls  Collections (Array, Hashtable, etc.)  DataSet, DataTable, DataView, DataReader  XML  One way snapshot model  Requires code to reapply to data model
  • 80. Data Binding What Is It?  Allows you to specify an expression  When the DataBind method of the control is called, the expression is evaluated and bound  DataBind for a single control (and sub controls)  Page.DataBind binds all controls on a page  Works for scalars, e.g. Label control  Works for lists, e.g. DropDown control, ListBox control, etc.  Enables the use of templates
  • 81. Data Binding Scalar Expressions  Data binding expression: <%# expression %>  Expression is evaluated when DataBind() is called <asp: Label id=label1 Text=<%# “The result is “ & (1 + 2) & “, the time is “ & DateTime.Now.ToLongTimeString() %> runat="server" /> public sub Page Load(s as object, e as EventArgs) if (Page.IsPostBack) then else Page.DataBind() end if end sub
  • 82. Data Binding Scalar Expressions  Demo: DataBinding1.aspx  Data binding to simple, scalar expressions
  • 83. Data Binding Simple Lists  Data binding a list creates a user interface element for each item in the list  Each item contains text (displayed to user) and an optional value (not displayed)  The simple list controls:  <asp:ListBox>  Single or multiple select  <asp:DropDownList>  <asp:RadioButtonList>  <asp:CheckBoxList>
  • 84. Data Binding Simple Lists  Steps to data bind a list control  Declare the list control  Optionally set DataValueField and DataTextField  Set its Data Source  Call DataBind() method
  • 85. Data Binding Simple Lists  Demo: DataBinding2.aspx  Data binding to simple lists
  • 86. Resources General Sites  http://msdn.microsoft.com/net/aspnet/default.asp  http://www.asp.net/  http://www.fmexpense.com/quickstart/aspplus/defau lt.htm  http://www.asptoday.com/  http://www.aspng.com/aspng/index.aspx  http://www.4guysfromrolla.com/  http://www.aspfree.com/  http://www.devx.com/dotnet/  http://www.ibuyspy.com/
  • 87. Starting ASP.NET Development  Web Site  Don’t use this, here for compatibility only  Each page is dynamically loaded into memory  Slow on first load after deployment  No need to recompile for code change
  • 88. Starting ASP.NET Development ..  Web Application  Recommended  Compiles all pages into one DLL  Faster on first load after deployment  Must recompile whole site for code change
  • 89. Web Project in Asp.net