basics of asp.net. 2 © uw business school, university of washington 2004 outline installing asp.net...
Post on 20-Dec-2015
217 views
TRANSCRIPT
© UW Business School, University of Washington 2004
2
Outline
• Installing ASP.NET and Web Matrix• Data Types• Branching Structure• Procedures and Functions• HTML Form• ASP.NET Server Controls• Page Events
© UW Business School, University of Washington 2004
3
ASP.NET Installation
• Requirement for Operating Systems– Windows 2000/2003, or Windows XP Professional or Home
• Install the following– MDAC (Microsoft Data Access Components)
• Download MDAC 2.8 at www.microsoft.com/data (not SDK)• Filename: MDAC_TYP.EXE (5.4 MB)
– .NET Framework Redistributable version 1.1• Download at www.asp.net• Click Download link at the top right part of the window and
choose to download .NET• Filename: dotnetfx.exe (23.7 MB)
– Web Matrix • Download at www.asp.net • Filename: WebMatrix.msi (1.3 MB)
© UW Business School, University of Washington 2004
4
ASP.NET Installation (Cont’d)Edit WebMatrix.exe.config file located at C:\Program files\Microsoft ASP.NET WebMatrix\v0.6.812\
<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <sectionGroup name="microsoft.matrix"> <section name="packages"
type="Microsoft.Matrix.Core.Packages.PackageListSectionHandler, Microsoft.Matrix"/> … </sectionGroup> </configSections> <startup> <supportedRuntime version="v1.1.4322" /> </startup> <runtime> …
Insert this part
© UW Business School, University of Washington 2004
5
First ASP.NET Program
• The @Page directive allows you to set the default properties for the entire page such as the default language
• Response object is used to send information to the browser
• Write is a method of the Response object, which allows you to send a string to the browser
http://infosys.badm.washington.edu/ebiz1/first.aspx
© UW Business School, University of Washington 2004
6
Other Examples
• TextBox.aspxhttp://infosys.badm.washington.edu/ebiz1/textbox.aspx
• ListandRadio.aspxhttp://infosys.badm.washington.edu/ebiz1/listandradio.aspx
© UW Business School, University of Washington 2004
7
Data Types
• Numeric• Text• Others
– Date
– Boolean
© UW Business School, University of Washington 2004
8
String
• Strings are variable in length so you don’t have to specify the number of characters in the string when you create the string object
• Example:Dim Name As String
Name = “John”
• String ConcatenationName = “John” & “ Halata”
© UW Business School, University of Washington 2004
9
Numeric Values
• Numeric Data Types
– Byte - stores an integer between 0 and 255
– Short - is a 16-bit number. Therefore, a short data type can only store values from -32,768 to 32,767
– Integer data type is a 32-bit whole number
– Long - is a 64-bit number
• Real number data types
– Single - represents a single-precision floating point number
– Double - supports larger numbers than the single data type
– Decimal - can store numbers up to 28 decimal places and is often used to store currency data
© UW Business School, University of Washington 2004
10
DateTime
• DateTime data type is used to store any dates
and times between 01/01/0001 and 12/31/9999
as mm/dd/yyyy and hh:mm:ss
• The date value is enclosed within a pair of
pound signs
Dim MyBirthday As DateTime MyBirthday = #3/22/2002#dateTime = #1:30:00 PM#
© UW Business School, University of Washington 2004
11
Boolean
• A Boolean data type only has two possible values, True value or False value
• Logical (Boolean) Operators– and, or, not
– Example
If number1 = 1 and number 2 = 2 Then
…
If not Page.IsPostBack Then
…
© UW Business School, University of Washington 2004
12
Branching Structure
• If…Then…End If• If…Then…Else…End If• Example:
If email = “Yes” Then
Message.Text = “We will send you an email.”
Else
Message.Text = “We will mail you a receipt.”
End If
© UW Business School, University of Washington 2004
13
Procedures
• Subroutines or sub-procedures do not return values and cannot be used in an expression value
• Create a Subroutine – Declared using the keyword sub
– Exit sub statement to exit the subroutine
– End with the keywords end sub
• Call keyword can be used to call a function or subroutine and is optional
© UW Business School, University of Washington 2004
14
Event Procedure
• You can intercept the event using an event handler– Events such as click are intercepted by event handlers
such as onServerClick
– An event handler is also known as an event procedure
– An event procedure is not executed until an event triggers the event procedure
– An event procedure does not return a value
• The Page_Load event procedure is triggered when the page is loaded into the browser
© UW Business School, University of Washington 2004
15
Functions
• A function is a block of code that is grouped into a named unit. – Built-in functions inherit from a .NET Framework
class
– User defined functions are declaredFunction GetStoreName() As Integer
'This function returns an integer
Return 23422
End Function
© UW Business School, University of Washington 2004
16
Passing an Argument to a Function
• A pair of parentheses with zero or more arguments, also known as parameters, which are passed to the function when it is called– If no arguments are passed, you use an empty pair of
parentheses– If multiple arguments are used, you use a comma to
separate each argument
© UW Business School, University of Washington 2004
17
Function Example
Function Add(ByVal i As Integer, ByVal j As Integer) As integer
Return i+j
End Function
Dim sum As integer
sum = Add(2, 3)
© UW Business School, University of Washington 2004
18
HTML Forms
• <Form> tags are used to ask user information.• Form has two default button types:
– Submit: to submit information to the server.
– Reset: to clear information
• Example<form id=“MyForm” runat=“server”>
…
<input type=“reset”>
<input type=“submit”>
</form>
© UW Business School, University of Washington 2004
19
ASP.NET Server Controls
• Two required attributes:– Runat=“server”
– ID=“…”
• ASP.NET code is never sent to the browser• All ASP.NET server controls will be converted
into HTML format before they are sent to the browser
© UW Business School, University of Washington 2004
20
<asp:label>
• Purpose: displaying text• Attributes
– Text
– BackColor
– ForeColor
– …
© UW Business School, University of Washington 2004
21
<asp:textbox>
• Purpose: user input• Attributes:
– textmode: one line (default), multiline, or passwrod
– rows: number of rows if textmode is set to multiline
– columns: number of columns if textmode is set to multiline
© UW Business School, University of Washington 2004
22
<asp:radiobuttonlist>
• Choice of one option excludes selecting other options
• Example
<asp:radiobuttonlist id="fair" runat="server">
<asp:listitem id="op1" runat="server" value="First class" />
<asp:listitem id="op2" runat="server" value="Coach" />
</asp:radiobuttonlist><br />
fairclass = fair.SelectedItem.value
© UW Business School, University of Washington 2004
23
<asp:dropdownlist>
• Selection from a list• Example
<asp:dropdownlist id="list1" runat="server">
<asp:listitem>Madrid</asp:listitem>
<asp:listitem>Oslo</asp:listitem>
<asp:listitem>Lisbon</asp:listitem>
</asp:dropdownlist>
© UW Business School, University of Washington 2004
24
Page Events
• The Page object consists of a variety of methods, functions, and properties that can be accessed within the code behind the page
• The first time a page is requested by a client, a series of page events occurs
• The first page event is the Page_Init event which initializes the page control hierarchy
• The Page_Load event loads any server controls into memory and occurs every time the page is executed
© UW Business School, University of Washington 2004
25
Postback
• The process of posting data back to a form is known as postback
• All server controls support postback by default
• The values that are stored with the page remain with the page