Introduction to ASP.NET - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Introduction to ASP.NET

Description:

PHP (Personal Home Pages) ASP (Active Server Pages) JSP (Java Server Pages) ASP.NET ... we display their record (and give them access to the Videos tables) ... – PowerPoint PPT presentation

Number of Views:5322
Avg rating:3.0/5.0
Slides: 40
Provided by: patmc2
Category:

less

Transcript and Presenter's Notes

Title: Introduction to ASP.NET


1
Introduction to ASP.NET
  • Patrick McKeown
  • MIS Department, Terry College
  • UGA

2
Introduction to Web Processing
  • With Web processing
  • 1. Browser sends URL to server
  • 2. Server sends the Web page back to browser
  • 3. User fills in Web page with data using browser
    and sends to server
  • 4. Software on browser processes the data and
    sends HTML to browser with the results of the
    processing
  • This process is shown on the next slide

3
Server Side Processing
Server running Web software
1. Browser sends URL
2. Server sends Web page
3. Browser sends data
4. Server returns results
PC client running browser
Query and results
Database server
4
Sending Data to Server
  • The Input Form objects (textboxes, radio buttons,
    and so on) are used to send data to server when
    Submit button clicked
  • The names of the objects are critical because
    they are link between HTML form and server
    software
  • For example, in ASP, the Request object links the
    Web page object names to VBScript variables, eg,
    for txtName, the statement might be
  • strName Request(txtName)
  • In this case, the variable Name is set equal to
    whatever was entered in the txtName textbox on
    the Web page

5
Processing Input Data
  • Once the data has been transferred from the
    textboxes or other input objects on the Web page
    to variables on the Web server software,
    processing can begin.
  • Processing is handled by the programming language
    (Perl, VBScript, Java, VB .NET, etc.)

6
Web Development
  • Web development creating applications that run
    on the server
  • Web development process
  • 1. Define problem (functional definition)
  • 2. Determine form of input from browser
  • 3. Determine form of output to browser
  • 4. Write and debug server-side code to process
    input to generate output to browser in form of
    HTML
  • 5. Test entire project
  • Final project must solve problem defined in 1st
    step

7
Commonly used Web Development Methods
  • CGI (Common Gateway Interface
  • PHP (Personal Home Pages)
  • ASP (Active Server Pages)
  • JSP (Java Server Pages)
  • ASP.NET

8
Comparison of methods
9
Creating ASP.Net Page
  • All textno special symbols so can use Notepad or
    other simple editor to create code
  • Pages are given an .aspx extension and run on
    .NET version of IIS
  • Start all pages with
  • DebugTrue
  • Where
  • Language parameter denotes that VB .NET is being
    used
  • ExplicitTrue requires explicit variable
    creation
  • DebugTrue provides more detailed explanation
    of errors

10
Aside Changes in VB. NET
  • All OO including inheritancemany new objects are
    now available
  • Based on XML
  • Some changes in data types, eg, Decimal instead
    of currency and variables are treated as objects
  • New Visual Studio design environment
  • By default, all arguments are passed by value
    instead of by reference
  • New file structuresee next page

11
New VB .NET File structure
12
Back to ASP.NET
  • In an ASP.Net page, tags and code are separated
    by delimiters
  • Tags appear and work in the of an ASP.NET
    document just like they do in a normal HTML page.
  • Code in the is interspersed in page
    surrounded by code delimiters, eg,
  • Multiple lines of code can be surrounded by one
    set of code delimiters,eg,
  • For TextSize 1 to 7

13
Displaying Variable Values
  • To output the result of an assignment statement,
    use the following statement in the of an
    ASP.NET page
  • HTML code here
  • For example, to compute taxes and total cost, see
    the code on the next page

14
Code to Compute Amount Due
Videoprice as Decimal Dim TaxRate, Taxes as
Decimal VideoPrice 2.99 TaxRate 0.07 Taxes
TaxRate VideoPrice TotalCost VideoPrice
Taxes The total cost is

15
Using Server Controls
  • In ASP and other types of server-side processing,
    HTML Input Form objects (textboxes, radio
    buttons, and so on) are used to send data to
    server when Submit button clicked
  • This requires creating two pagesan html form
    page to send the data and an ASP, PHP, or other
    page to receive the data.
  • With ASP.NET, the aspx page does it all with
    something called Server controls.

16
Server Controls (cont.)
  • Server controls are a part of the ASP.NET page
    but send an image to the browser that accepts the
    data and returns it to the ASP.NET page.
  • The names of the server controls are critical
    because they are the link between the server
    controls and the variables that carry out the
    processing.
  • The form of a server control is shown in the next
    slide.

17
Server Controls
  • The form of a server control is
  • label onclicksubprogram name runatserver
    /
  • Where
  • Control_type can be
  • Label
  • Textbox
  • Listbox
  • Button
  • Various others
  • Id is the name you assign the control
  • Text is the text or caption associated with
    control
  • Button is used to start processing

18
Server Control Properties
  • The various server controls have both properties
    and methods and can respond to events
  • For example, a Label server control has an id
    property (its name) and a text property (what it
    displays)
  • While id properties are assigned when the control
    is created, the text property may be assigned
    then (often used for labels that are descriptors)
    or later during processing (used for textboxes or
    labels that display the output of processing.)
  • The Onclick method of the button must be defined
    by the programmer though a subprogram that is all
    VB. NET codenot html.

19
A Simple Input/Output Example
  • Enter your name and two numbers
  • Display your name, the two numbers and the sum of
    the two numbers
  • Use two types of output
  • Response.write (used to output to Web page
    immediately)
  • Assign a string or value to text property of
    label control either when the control is created
    or during processing

20
The ASP Tags First
id"lblNameInput" text"Input your name "
runat"server"/ runat"server"/
text"Input 1st Number " runat"server"/ xtbox id"txtFirstNum" runat"server"/
abel id"lblInput2" text"Input 2nd Number "
runat"server"/ runat"server"/
text"Sum Numbers" onclick"Sum_Click"
runat"server"/

id"lblFirst" runat"server"/ id"lblSecond" runat"server"/ id"lblSum" runat"server"/
21
Explanation of Server Controls
  • simply indicates you
    should run this form on the server
  • Each label and textbox combination creates an
    input box preceded by a Label.
  • For example, the first two statements after the
    tag causes the following to be
    displayed

Label lblNameInput
  • The last three lines create labels that will
    contain the output values for the page
  • The text properties will be assigned in the
    subprogram Sum_Click

22
Input Controls
23
Carrying out the Processing
  • Processing should take place when the button is
    clicked. The OnClick method of the button is
    carried out by setting it equal to the name of
    the subprogram
  • The processing component is shown in the next
    slide.
  • Note that it starts with
    and ends with . The tags are
    used to define a subprogram of all code
  • Note that the name of the subprogram is
    Sum_Click which is the same name as the OnClick
    method of the button was assigned to

24
The Sum_Click Subprogram
sub Sum_Click(Sender as
object, e as eventargs) dim MyName as string,
First, Second, Sum as integer MyName
txtName.text Response.write("My name is"
MyName "
") First cint(txtFirstNum.text
) Second cint(txtSecondNum.text) Sum
First Second lblFirst.text "The first
value is " cstr(First) lblSecond.text
"The second value is " cstr(Second) "
"
lblSum.text "The sum of the two values is "
cstr(Sum) "
" end sub
1 2 3 4 5 6 7 8 9 10 11 12 13
NOTE the numbers are for discussion and are NOT
part of the code!
25
Explanation of Program
  • Indicates this is VB .NET code that should be run
    at the server
  • Declares the name of the subprogram (ignore the
    parameters after the subprogram name)
  • Declare variables
  • Set the MyName variable the name in the textbox
  • Output the name in the textbox with
    response.write method
  • Set integer variable to contents of textbox
  • Ditto above
  • Sum two integer variables
  • Set the text property of the label, lblFirst,
    created in the asp part of the program equal to
    the first value
  • Repeat above operation for second value
  • Repeat above operation for sum value
  • End the subprogram
  • Turn off script

26
Using ASP.NET with Databases
  • ASP.NET can be used to work with DAO, ADO, or
    ADO.NET databases
  • ADO.NET is a disconnected database that creates a
    copy of matching records/tables in memory
  • The key element of ADO.NET is the DataSet which
    can be records and or tables
  • We will use the Vintage Video Case as an example
    of using ASP.NET to work with a database

27
Vintage Video Relational Database
Status
28
Steps in ASP.NET Database Access
  • Create Server Controls for input
  • Import Namespace files
  • Create database objects in subprogram
  • Use input from server controls to construct a SQL
    query also construct string containing
    information about location of database
  • Use objects to run the query against the database
    to create the dataset consisting of the records
    that match the query
  • Display or process records in dataset

29
Database Demo Login page
  • To demonstrate working with a database, lets
    look at how to login into the Vintage Videos
    system
  • The login page is shown below

30
Step 1 Server Controls for Login Page
Login Page
Welcome to Vintage Videos online
access. Please input your telephone
number and e-mail address. When completed, click
the Submit button.
Telephone Number runat"server"/ E-mail address
PonclickSearch_Click runat"server"/
RM
31
Step 2 Importing Files
  • Import required .NET library (Namespace) files
    immediately after the statement

32
Step 3 Create database objects
  • Create various database objects and declare
    needed variables as shown on the next slide
  • sub Search_Click(Sender as object, e as
    eventargs)
  • Dim Connect as oleDbConnection New
    OleDbConnection
  • Dim Adapter as oleDbDataAdapter new
    OledbDataAdapter
  • Dim VintageDS as Dataset New Dataset
  • Dim ConnectionString, SelectStatement as string,
    NumRows as Integer
  • In this case, Connect and Adapter are new
    objects
  • and VintageDS is a new dataset
  • ConnectionString and SelectStatement are strings
    we will use to query the database and NumRows
    will be used to check number of records returned

33
Step 4 Create SQL Query and Connection to databse
  • Assume we are working with Access 2000 and want
    to find the member with the phone number input
    earlier
  • SQL string is then
  • SelectStatement "Select from Members where
    Phone_Number _
  • "'" txtPhoneNum.text "'
  • Also assume that we are working on a server
    running IIS and the database is stored at
    c\vintage.mdb
  • The Connection string for our situation is then
  • ConnectionString "ProviderMicrosoft.Jet.OLEDB.4
    .0" _
  • "Data Sourcec\Vintage.mdb
  • The Data Source statement here refers to the Web
    server.

34
Step 5 Execute Query
  • Once the SelectionString and ConnectionString
    have been created, the next step is to execute
    the query using the Connect and Adapter objects
    created earlier using these statements
  • Connect.Connectionstring Connectionstring
  • Adapter.Selectcommand new oleDbCommand(Selectst
    atement, connect)
  • Adapter.SelectCommand.connection.open
  • Adapter.Fill(VintageDS, "Members")
  • The first statement sets the Connect objects
    Connectionstring property to the ConnectionString
    variable created earlier
  • The second statement creates a new object that
    holds the query string
  • The third statement actually executes the query
  • The fourth statement fills the dataset,
    VintageDS, and names the table we are creating in
    itpossible the same as a table in the database
    but not necessarily

35
Step 6 Processing the DataSet
  • Once the dataset is filled, we can check to see
    if there were any matching records for the query
  • We first set the label, numrows, to the number of
    rows in the dataset table
  • We then check to see if numrows is zero. If it
    is, we post a message that user is not a member
  • If numrows is not zero, we display their record
    (and give them access to the Videos tables)

36
Step 6 (cont.) Displaying the Results
  • If there is a record in the database matching
    the phone number, we can display it with the the
    datagrid server control in the design (runatserver section
  • To use MembersGrid datagrid, we add these
    statements when numrows 0
  • Membersgrid.datasource VintageDS.Tables("Member
    s")
  • Page.Databind
  • The first statement links Membersgrid to the
    dataset and the second statement actually moves
    the data.
  • Lets put the code for database access together
    on the next page

37
Debug"True" sub
Search_Click(Sender as object, e as eventargs)
Dim Connect as oleDbConnection New
OleDbConnection Dim Adapter as oleDbDataAdapter
new OledbDataAdapter Dim VintageDS as Dataset
New Dataset Dim ConnectionString,
SelectStatement as string, NumRows as Integer
SelectStatement "Select from Members where
Phone_Number" _ "'" txtPhoneNum.text "'
ConnectionString "ProviderMicrosoft.Jet.OLEDB.4
.0" _ "Data Sourcec\inetpub\wwwroot\Vintage.
mdb" Connect.connectionstring
connectionstring adapter.selectcommand new
oleDbCommand(Selectstatement, connect)
Adapter.SelectCommand.connection.open
Adapter.Fill(VintageDS, "Members") NumRows
VintageDS.Tables("Members").Rows.Count if
NumRows0 then response.write("Not a
member") else Membersgrid.datasource
VintageDS.Tables("Members") Page.Databind
end if end sub
38
The Completed Project
  • Entering this code in Notepad, saving it as
    login.aspx on the Web server, and running it with
    a valid telephone number, eg, 706-555-1234 should
    result in a display of data about this person as
    shown on the next page
  • Change the area code to 941 and you should
    receive a message that this person is not a
    member

39
Matching Phone Number
Write a Comment
User Comments (0)
About PowerShow.com