asp net basic 1
TRANSCRIPT
-
8/3/2019 ASP Net Basic 1
1/41
Introduction to ASP.NET
Prepared By : Rajeswari Badi (190985)
-
8/3/2019 ASP Net Basic 1
2/41
-
8/3/2019 ASP Net Basic 1
3/41
Key Learning Objectives
Introduction to Web Technology
ASP.NET Architecture
ASP.NET Web Forms and Controls
ASP.NET Programming using VS.NET
ASP.NET Security
ASP.NET Deployment
ASP.NET Application Configuration
Introduction to ASP.NET Web Services
ASP to ASP.NET Migration and Performance
-
8/3/2019 ASP Net Basic 1
4/41
10 Reasons You Love ASP.NET!
Much simpler page development model
Clean separation of code and content
Ability to use compiled languages
Deploy and upgrade running apps with XCOPY
Support for wide range of mobile devices
Great tools support
Web farm scalable session state
Modular, well-factored architecture
Automatically detects and recovers from errors Its really, really fast!
-
8/3/2019 ASP Net Basic 1
5/41
Introduction to Web Technology
Request Response Model
Web Server
Web Client
Presentation Layer
Scripting Client / Server side
State Less
State management Levels Page/Session/Application
Web Page Actions Get/Post
-
8/3/2019 ASP Net Basic 1
6/41
(Or Will After This Talk!)
Pages Services
ASP.NET Architecture
HTTP Runtime
-
8/3/2019 ASP Net Basic 1
7/41
Runtime Compilation
ASPX
File
Request
ASPX
Engine
Parse
Gend
Page
Class
Generate
Response
Request
Instantiate
Response
Code-
behind
class
Page
DLL Instantiate,
Process and
Render
Compile
-
8/3/2019 ASP Net Basic 1
8/41
Page Life Cycle
RequestPage
Initialized
Response
Request
Response
Page Load
View State
Saved
OutputRendered
Page
Unload
ControlProperties
Updated
View State
Restored
Control
Event
Handlers
-
8/3/2019 ASP Net Basic 1
9/41
Code
behind
ASP.NET Page Execution Cycle
IIS
ASP.NET Runtime
Instantiate controls
Parse .aspx file
Generate page class
Request .aspx file
Response
Client Server
-
8/3/2019 ASP Net Basic 1
10/41
ASP.NET Web Forms
-
8/3/2019 ASP Net Basic 1
11/41
What WebForm Offers
DeviceSpecific Behaviour Browser-Independence
Less Code
Server Side ControlsServer Side Controls Less Code
Drag and Drop
Validation ControlsValidation Controls Declarative Programming
User ControlsUser Controls Reusability
-
8/3/2019 ASP Net Basic 1
12/41
Web Forms
Dramatically easier, more productive
Requires a lot less code for a given job
Enables much cleaner code organization
Server UI Controls provide encapsulation
VB-like, event-driven programming model
Functionality and rendering
Cross browser, cross device
Separation of code from content
Developers, designers can work independently Executed via CLR as native code
VB, C#, JScript or any other .NET language
-
8/3/2019 ASP Net Basic 1
13/41
Separation of Code, Content
ASP page combines declarative tags (HTML, ASP directives, servercontrols and static text) with code
ASP.NET separates the code and tags for better manageability
Form1.asp
code
Form1.aspx
code
Form1.vb
single file separate files
-
8/3/2019 ASP Net Basic 1
14/41
ASP.NET Server Controls(1 of 2)
Server controls encapsulate behavior
Declarative, tag with runat="server"
Generate HTML that is sent to the client
Can support multiple client types
DHTML, HTML 3.2, WML, etc.
Process input sent from client
Bind to data in Forms collection
Fire events for notifications
-
8/3/2019 ASP Net Basic 1
15/41
ASP.NET Server Controls(2 of 2)
Allow look and feel to be customized
Template properties allow fine grained control Are stateless on the server
ViewState travels with the page or URL
-
8/3/2019 ASP Net Basic 1
16/41
Server Controls
Server-programmable objects
Properties, method and events
Encapsulate behavior, rendering
Can render differently to support multiple browsersor other Web clients
Mobile device support should be in beta 2
Users can create server controls
And derive from existing controls!
Uses a special tag (runat=server)
-
8/3/2019 ASP Net Basic 1
17/41
Class Hierarchy
System.Web.UI.
WebControlsListControl
ListBox
CheckBoxList
Button
Table
WebControl
System.Web.UI.Control
System.Object
TextBox
......
-
8/3/2019 ASP Net Basic 1
18/41
How Do Server Controls Work?
When the ASP.NET page is executed:
Creates action and method attributes of form
Adds unique id and name attributes to controls Adds value attribute to controls
Adds a Hidden control to the form to save view stateinformation(see as __VIEWSTATE field)
The resulting HTML is sent down to the client
-
8/3/2019 ASP Net Basic 1
19/41
Code Behind Pages
ASP.NET includes support for all CLR languages
VB, C#, JScript and many others
Still supports tags for backwards
compatibility Code is compiled though, not interpreted
For maximum programming power use ServerControls
Write code for them using all the features of yourfavorite language and IDE
Very VB-like get access to properties, methods andevents
-
8/3/2019 ASP Net Basic 1
20/41
Power of Code Behind
Gives your ASP.NET applications access to the fullpower of the CLR
Compiled code
All language features
strong typing
early binding
complete language set
Structured error handling
API access
Etc, etc, etc
-
8/3/2019 ASP Net Basic 1
21/41
Validation in ASP
Write custom code every time
Client-side code becomes interwoven with content
Server-side code works but you have to manually
propagate state between trips to the client Usually lots of tedious code snippets that take a lot
of time to get right
-
8/3/2019 ASP Net Basic 1
22/41
Validation Controls in ASP.NET
Added to Web Form like any other server control
Controls validation for a variety of requirements
Required field
Range checking Pattern matching
You can attach more than one validation control toan input
Only works with a subset of controls
-
8/3/2019 ASP Net Basic 1
23/41
Controls You Can Validate
SelectedItem.ValueRadioButtonList
SelectedItem.ValueDropDownList
SelectedItem.ValueListBox
TextTextBox
ValueHtmlInputFile
ValueHtmlSelect
ValueHtmlTextArea
ValueHtmlInputText
Validation PropertyControl
-
8/3/2019 ASP Net Basic 1
24/41
Types of Validation
Required Field Input MUST be entered
Compare Input must match a pre-defined value or other control value
Range Input must be within a lower- and upper-range
Regular Expression Input must conform to a regular expression pattern
Custom Uses a custom function you create
Summary Summarizes the results of all the validation controls
-
8/3/2019 ASP Net Basic 1
25/41
Where Does Validation Occur?
Always on the server
If your browser supports DHTML, it will also
validate on the client by default You can disable client-side validation Set the Pages ClientTarget property to "Downlevel"
It will still validate on the server
Prevents bypassing client security
Happens when you submit the page
-
8/3/2019 ASP Net Basic 1
26/41
Displaying Validation Errors
All validation controls are checked If all pass muster the Pages IsValid property is set to
True
When input fails validation, the associatedvalidation controls Text property is displayed If the Text property is empty, it displays the
ErrorMessage property
A summary validation control displays theErrorMessage properties for all the Validationcontrols on the page
This is only displayed when the pages IsValid property isFalse
-
8/3/2019 ASP Net Basic 1
27/41
ASP Data Binding
No real notion of binding to an HTML control Use ADO Connections, Commands and Recordsets
to retrieve data Manually iterate through Recordset results to build
an HTML Table or fill the contents of a Select Building the HTML is relatively easy; making it look
good takes longer HTML and ASP code intermingle
Recordsets are usually the only data source
-
8/3/2019 ASP Net Basic 1
28/41
Data Binding in ASP.NET
Choices, Choices, Choices
Bind to Properties Customer:
Bind to Collections
Bind to Expressions Contact:
Bind to Method Results Outstanding Balance:
Bind to DataSets
Grid.DataSource = myDataSet.Tables(0)
-
8/3/2019 ASP Net Basic 1
29/41
The DataBind Method
DataBind is a method on the Page object and allServer controls
Calling it once on a page will bind all child controls
Binding syntax is NOTevaluated unless/until DataBind
Binding expressions just work as long as theresult is the expected data type
You may need to coerce to the appropriate type, such as
myVal.ToString
-
8/3/2019 ASP Net Basic 1
30/41
Complex Binding
Most applications are going to talk to a big backenddatabase like SQL Server
This is more difficult than simple binding
Going to use ADO.NET Have to deal with Inserts, Updates and Deletes
Have to manage multiple interfaces for each type ofoperation
-
8/3/2019 ASP Net Basic 1
31/41
Complex Binding in ASP
Usually is a complicated interface
Different pages for different actions
Different code to render results, accept changes, etc.
Lots of state management that needs to occur Can quickly become a time-consuming process
-
8/3/2019 ASP Net Basic 1
32/41
Complex Binding in ASP.NET
More complicated than simple binding, but still much easierthan ASP
Bindable server controls like DataGrid are big time savers
Supports themes out of the box to give a professional
presentation and appearance ViewState of page gives big perf benefits for maintaining
state
Supports properties and events to let you use the sameinterface for Updates and Deletes
-
8/3/2019 ASP Net Basic 1
33/41
One Grid Does It All
DataGrid offers the ability to edit, delete and update all inthe same page
You can add special EditCommand buttons
Edit
Update Cancel
Delete
There are event handlers associated with each button putyour code there to update the database
Using a TemplateColumn in a grid gives you completecontrol over the GUI
You can put any HTML control in a cell
-
8/3/2019 ASP Net Basic 1
34/41
ASP.NET Caching
-
8/3/2019 ASP Net Basic 1
35/41
Caching in ASP.NET
Lots of things you can cache Cache sets of data Cache fragments of a page Cache an entire page
Lots of control over how its cached Cache based on time (keep it for x seconds) Cache based on content (keep a copy for each unique
value in this dataset) Cache based on dependencies (keep a copy until a file or
other cache item changes
-
8/3/2019 ASP Net Basic 1
36/41
Getting Cached Items
Try retrieving item from cache Item retrieval is based on a key
MyValue = Cache(someKey)
If the return value is Nothing, create it
When you create a cache item you set the desiredlifetime and rules
Cache persists until expiration or application isrecycled
Use Cache.Insert to create item
-
8/3/2019 ASP Net Basic 1
37/41
Creating Cached Items
Cache based on file dependency Expires when authors.xml changes
Cache.Insert("MyData", Source, NewCacheDependency(Server.MapPath("authors.xml")))
Absolute expiration
Expires in one hour Cache.Insert("MyData", Source, null, DateTime.Now.AddHours(1),
TimeSpan.Zero)
Relative expiration Expires 20 minutes after it was last used
Cache.Insert("MyData", Source, null, DateTime.MaxValue,TimeSpan.FromMinutes(20))
-
8/3/2019 ASP Net Basic 1
38/41
Caching Support
Full page output caching
Vary by params, language, user-agent
Fragment Caching
Enables portions of pages to be cached
Extensible Cache API
Developers can cache arbitrary objects
Multiple expiration policies, file change invalidation
-
8/3/2019 ASP Net Basic 1
39/41
Caching Directive
Add a directive to the page
Set the Duration property for how long it should beserved from cache
Set the VaryByParam to whatever GET/POSTparameters should cause a new item to be cached
Example:
-
8/3/2019 ASP Net Basic 1
40/41
Page Fragment Caching
Allows you to mark certain regions of your page for caching Requires using Web Controls (.ascx files)
Each Web Control is a separate file Each Web Control can have its own Duration that is separate
from its Parent Just include the directive in the control Cache can be purged by duration or changing content in one of
the Web Controls child controls Uses VaryByControl parameter in OutputCache When the value of that control changes, a new entry is added to the
cache for the duration
-
8/3/2019 ASP Net Basic 1
41/41
Thank You