Top Banner
CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009
22
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

CIS 451: ASP.NET Objects

Dr. Ralph D. WestfallJanuary, 2009

Page 2: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Object Oriented Programming many popular newer programming

languages are object-oriented C++, Java, JavaScript

Visual Basic.NET is a true object-oriented (OO) language in contrast to VB 6 (which however

did have objects with very useful properties)

Page 3: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

What Is an Object? 3 types of things grouped together

properties (like variables: descriptive) like a "super" variable (cf. hours PM)

methods (like functions: actions) events (things that it responds to)

similarities with real world objects car (properties? methods? events?) dog " "

Page 4: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Object Features properties: name/value pairs

age = 21; height = 66"; weight = 135#; methods: code that does something

calculations, write to screen, send e-mail may have either/both of following:

parameters (inputs) return values (outputs)

Page 5: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Object Features - 2 events: things happen, object responds

to them like a method, but triggered externally

user clicks a button, or time runs out can have parameters and/or return values

asynchronous: can occur at any time rather than scheduled, or at same time as

something else (synchronous)

Page 6: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Other Object Concepts class = template or general model instance of class has specific attributes telephone = class, my phone =

instance encapsulation: details of object hidden

inside a "black box" only need to know the interface: how to

call the methods and what the inputs and/or outputs are

Page 7: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Other Object Concepts - 2 "dot" notation identifies attributes

and methods of objects Request.TotalBytes Request.QueryString.Count

Count (of arguments) in QueryString is a property of Request Object

Response.Write() Write is a method of Response Object

Page 8: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

ASP Core Objects Request: messages from caller (e.g.,

web page or process) Response: messages to caller

(browser) Server: variables and utility functions Application: data storage in memory

for all web pages in the application Session: identifies individual user

interactions

Page 9: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Request Object html or another asp file requests an asp

file Request Object has information from

page that requested the asp file information is stored in "collections"

contain pairs of variable names and their values (name/value pairs)

data values can be accessed by item name

Request.QueryString("page")

Page 10: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Request Object Data "get" method in HTML calling page

<form action="buya.aspx" method=get> "get" appends data to URL (URL encoding) limit around 1000 characters (256 –

2000+) data available in Request.QueryString

"collection," indexed by name of form element

Request.QueryString("page") form has textbox, textarea, checkbox, radio

button, or etc. element with name="page"

Page 11: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

URL Encoding ? after URL shows start of data pairs of: name=value & (ampersands) between pairs + between separate words (= space) special characters coded as %nn (+ is

%2B) http://www.company.com/search.asp? …?cust=Jabbar&address=231+10th+St

example: try doing a Yahoo search

Page 12: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Request Object Data - 2 "post" method in HTML calling page

<form action="buya.aspx" method=post> sends data by a separate route size is essentially unlimited data available through Request.Form

"collection," indexed by name of form element

Request.Form("prod1") form has textbox, textarea, checkbox, radio

button, or etc. element with name="prod1"

Page 13: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Get versus Post get (Request.QueryString)

[object.property]) better for debugging (can look at query

string in URL box on browser) post (uses Request.Form)

can handle more data safer (less susceptible to hacking)

always use post for database updates

easy to convert Request.QueryString to Request.Form with global search/replace

Page 14: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Using QueryString in an aspx File

can create the same effect sending from an aspx file as from a html fileResponse.Redirect("rsp.aspx?Name=" & _

this.txtName.Text & "&LastName=" & _

this.txtLastName.Text) values are URL encoded and visible in

browser address of destination page one way to migrate from html to aspx

Page 15: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Response Object sends information to client

can control when and how to send it can control caching/expiration of

page can send parts or all of a web page

to client

Page 16: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Response Methods Response.Write(x1 [& " " & x2 [& ...]])

x1 etc. can be anything printable (text, #s, etc., or functions that return printable characters)

.NET has parentheses hold argument(s)

<%= x1 [& " " & x2 [& " " & etc.]%> same effect as Response.Write, in

less space less efficient (don't use <%= a lot)

Page 17: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Response Methods - 2 redirecting to another pageResponse.Redirect("buya.aspx") stops processing on current page and

goes to the other page can go to external pages too

Page 18: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Server Transfer Method can also use to redirect to another

page, but only if it's on same serverServer.Transfer("buya.aspx") doesn't change URL in browser

address comparison of Response.Redirect and

Server.Transfer

Page 19: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Exercise: Form Processing use Dreamweaver to create a form

that uses 8+ form elements/variations in its Windows>Objects>Forms toolbar

set name property for each element select options (e.g., text input can be

single or multiline, or password) see HTML Form Reference for syntax

save file as a .html file

Page 20: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Exercise: Form Processing - 2 use Visual Studio to

create a project add the .html file you created on the

previous page to the project create a .aspx file with Response.Write

statements to print inputs/selections from each input element from the .html file

test it on your workstation or computer

Page 21: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Multiple Selection Data can allow multiple selections in a

list box on a form <select size=2 name="loc" multiple> <option>Paris</option > <option>Sydney</option > <option>Buenos Aires</option > </select> may send multiple items with

same name ("loc" in this example)

Page 22: CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.

Multiple Selection Data - 2 For intI = 1 to _ Request.Form("loc").Count Response.Write _ (Request.Form("loc")(intI)) Next

note dot connecting Form object's ("loc") item to Count