Download presentation
Presentation is loading. Please wait.
1
Basics of ASP.NET
2
2 © UW Business School, University of Washington 2004 Outline Installing ASP.NET and Web Matrix Data Types Branching Structure Procedures and Functions HTML Form ASP.NET Server Controls Page Events
3
3 © UW Business School, University of Washington 2004 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)www.microsoft.com/data Filename: MDAC_TYP.EXE (5.4 MB) –.NET Framework Redistributable version 1.1 Download at www.asp.netwww.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.netwww.asp.net Filename: WebMatrix.msi (1.3 MB)
4
4 © UW Business School, University of Washington 2004 ASP.NET Installation (Cont’d) Edit WebMatrix.exe.config file located at C:\Program files\Microsoft ASP.NET WebMatrix\v0.6.812\ … … Insert this part
5
5 © UW Business School, University of Washington 2004 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
6
6 © UW Business School, University of Washington 2004 Other Examples TextBox.aspx http://infosys.badm.washington.edu/ebiz1/textbox.aspx ListandRadio.aspx http://infosys.badm.washington.edu/ebiz1/listandradio.aspx
7
7 © UW Business School, University of Washington 2004 Data Types Numeric Text Others –Date –Boolean
8
8 © UW Business School, University of Washington 2004 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 Concatenation Name = “John” & “ Halata”
9
9 © UW Business School, University of Washington 2004 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
10
10 © UW Business School, University of Washington 2004 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#
11
11 © UW Business School, University of Washington 2004 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 …
12
12 © UW Business School, University of Washington 2004 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
13
13 © UW Business School, University of Washington 2004 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
14
14 © UW Business School, University of Washington 2004 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
15
15 © UW Business School, University of Washington 2004 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 declared Function GetStoreName() As Integer 'This function returns an integer Return 23422 End Function
16
16 © UW Business School, University of Washington 2004 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
17
17 © UW Business School, University of Washington 2004 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)
18
18 © UW Business School, University of Washington 2004 HTML Forms 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 …
19
19 © UW Business School, University of Washington 2004 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
20
20 © UW Business School, University of Washington 2004 Purpose: displaying text Attributes –Text –BackColor –ForeColor –…
21
21 © UW Business School, University of Washington 2004 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
22
22 © UW Business School, University of Washington 2004 Choice of one option excludes selecting other options Example fairclass = fair.SelectedItem.value
23
23 © UW Business School, University of Washington 2004 Selection from a list Example Madrid Oslo Lisbon
24
24 © UW Business School, University of Washington 2004 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
25
25 © UW Business School, University of Washington 2004 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
26
26 © UW Business School, University of Washington 2004 Compiling the Page Class
27
27 © UW Business School, University of Washington 2004 Recap Basics of the VB syntax HTML form and ASP.NET server controls
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.