Upload
erica-ross
View
224
Download
1
Embed Size (px)
Citation preview
1
Presented by Bikash Shrestha
2
What is ASP.NET or ASP+?
ASP.NET/ASP+ is a programming framework built on the common language runtime that can be used on a server to build powerful Web applications.
3
.NET Architecture
4
What is ASP.Net?
Next generation of ASP New paradigm for server side
scripting Part of new .net framework
5
Why ASP.NET?
Easy Programming Model Avoids spaghetti code Great pages with far less code than ASP Easy display data Easy validating user input Easy uploading files Works in all browser ( including
Netscape, Opera, AOL, and IE)
6
Why ASP.NET?
Flexible Language Options ASP support VBScript and Jscript ASP.NET supports 25 .NET languages Includes built in support for VB.NET, C+
+, C#, and JScript.NET
7
Why ASP.NET?
Rich Class Framework .NET Framework offers over 4500
classes that encapsulates rich functionality like
XML, data access, file upload, regular expressions, image generation, performance monitoring and logging, transactions, message queuing, SMTP mail, and more
8
Why ASP.NET?
Improved performance & Scalability 3 to 5 times faster than ASP
Due to dynamic compilation
Rich Output Caching Eliminates the need to query the database
on every request improve performance of data-driven
pages
9
Compatibility
Not fully compatible with ASP, however can run side by side with older versions.
Instead of .asp it uses .aspx extensions.
10
Syntax and Semantics
ASP.NET fully API-compatible with traditional ASP except Request() Request.QueryString() Request.Form()
ASP.NET returns string ASP returns array of strings
11
For ASP.NET
Cnn.com/Test.aspx?value=45&value=600
would be accessed as follows: <% ' Below line outputs: "45, 600"
Response.Write(Request.QueryString("values"))
' Below line outputs: "45" Response.Write(Request.QueryString.GetValues("values")(0)) %>
12
Syntax & Semantics
ASP.NET pages support only a single language.
ASP.NET page functions must be declared in <script runat=server> blocks unlike <% %> in ASP.
13
Syntax & Semantics
Page-render functions are not supported
Example IN ASP <% Sub RenderSomething() %>
<font color="red"> Here is the time: <%=Now %> </font> <% End Sub %> <% RenderSomething
RenderSomething %>
14
Syntax & Semantics
Example IN ASP.NET<script language="VB" runat=server> Sub RenderSomething()
Response.Write("<font color=red> ") Response.Write("Here is the time: " &
Now) End Sub </script>
<% RenderSomething() RenderSomething() %>
15
Display Hello World in ASP.NET
Save the file as an .aspx extension
<html> <body bgcolor="yellow">
<center> <h2>Hello W3Schools!</h2> </center>
</body> </html> first aspx code to display "hello world"
16
Limitation of Classic ASP
Code has to be placed where the output apprears Impossible to separate ASP code from HTML Eg. <html>
<body bgcolor="yellow"> <center> <h2>Hello W3Schools!</h2>
<p><%Response.Write(now())%></p> </center> </body>
</html>
17
ASP .NET - Server Controls
The "spaghetti-code" problem solved with server controls.
Server controls are tags that are understood by the server.
Three kinds of server controls: HTML Server Controls - Traditional HTML tags Web Server Controls - New ASP .NET tags Validation Server Controls - For input validation
18
HTML Server Controls
HTML tags understood by server.
Comparable to JavaScript but run at server
Regular HTML elements are, by default, treated as text.
Add runat="server" to HTML elements to make it programmable and to be run at server.
must be within a <form> tag
id attribute is added to identify the server control
They can be used at a run time.
19
Example of HTML Server Control
<script runat="server"> Sub Page_Load
link1.HRef="http://www.w3schools.com" End Sub
</script>
<html> <body> <form runat="server"> <a id="link1" runat="server">Visit W3Schools!</a> </form> </body>
</html> anchor example
20
HTML Server Control contd…
HTMLButtonHTMLImage 2HTMLInputbuttonHTMLInputCheckboxHTMLInputHiddenHTMLInputImageHTMLInputRadiobuttonHTMLTableHTMLTextarea
21
ASP .NET - Web Server Controls
ASP .NET tags understood by the server
Like HTML Server Controls, require runat="server" to execute in server
Like HTML Server Controls, require id.
Does not map to HTML Elements.
More complex elements
22
ASP .NET - Web Server Controls contd…
AdRotator
Calendar
CheckboxList
DropdownList
Hyperlink
Image
Label
Listbox
Literal
Panel
RadiobuttonList
Table
23
ASP .NET - Validation Server Controls
Used to validate user-input
If invalid data, display an error message to the user
By default, page validation performed when Button, ImageButton, or LinkButton control is clicked
Prevent validation by changing CausesValidation property to false.
24
ASP .NET - Validation Server Controls contd…
CompareValidator
CustomValidator
RangeValidator
RegularExpressionValidator
RequiredFieldValidator
Validationsummary
25
ASP .NET - Events
An Event Handler is a subroutine that executes code for a given event.
Example of The page load event
Example of The Page.IsPostBack Property
26
ASP .NET Web Forms
All server controls must appear within a <form runat="server" > tag
By default the page is submitted to itself. If action is set then method=“post “ by default as in
Classic ASP An .aspx page can only contain ONE
<form runat="server"> control! Submitting a Form
Example Self Posting
27
ASP.NET Data Binding
Data binding is used to fill lists with selectable items from an imported data source, like a database, an XML file, or a script.
Usually uses an imported source. the data is separated from the HTML any changes to the items are made in the separate
data source.
The following controls support data binding asp:RadioButtonList asp:CheckBoxList asp:DropDownList asp:Listbox
28
Data Binding - ArrayList Object
The ArrayList object is a collection of items containing a single data value.
Example - ArrayList RadioButtonList
29
Data Binding - The Hashtable Object
The Hashtable object contains items in key/value pairs.
Cannot sort items.
Example- Hashtable DropDownList
A Hashtable object may automatically generate the text and values to the following controls:
asp:RadioButtonList asp:CheckBoxList asp:DropDownList asp:Listbox
30
Other Data Binding Controls
SortedList object It combines the features of both the ArrayList object and
the Hashtable object. XML Files
We can bind a XML files to get data. Example of XML Data Binding
The Repeater It is used to display a repeated list of items that are bound
to the control.
May be bound to a database table, an XML file, or another list of items example of Repeater
The DataList Same as Repeater, except it adds a table around the data
items by default. DataList DataList <Alternate>
31
ASP.NET Database connection
To work with databases we need ADO .NET, which is a part of the .NET Framework and it
is used to handle data access.
What is ADO .NET? part of the .NET Framework consists of a set of classes to handle data access is entirely based on XML unlike ADO, has no Recordset object
Example of :Database connection - Repeater control
32
Helpful Hints
Most of my work are from http://www.w3schools.com/ http://www.asp.net/Tutorials/quickstart.aspx http://www.microsoft.com/net and Beginning ASP.NET 1.0 with Visual Basic.NET
published by wrox Programmer to Programmer ISBN 1-861007-33-7
Also to download this slides you can check at http://fall2003.cs.mnsu.edu/shresb2/aspPresentation.ppt
33
Thank you
Open for questions or concerns