CIS 451: ASP.NET Objects - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

CIS 451: ASP.NET Objects

Description:

in contrast to VB 6 (which however did have objects with very useful properties) ... Get versus Post. get (Request.QueryString) [object.property] ... – PowerPoint PPT presentation

Number of Views:163
Avg rating:3.0/5.0
Slides: 23
Provided by: RalphWe2
Category:
Tags: asp | cis | net | objects

less

Transcript and Presenter's Notes

Title: CIS 451: ASP.NET Objects


1
CIS 451 ASP.NET Objects
  • Dr. Ralph D. Westfall
  • January, 2009

2
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)

3
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 " "

4
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)

5
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)

6
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

7
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

8
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

9
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")

10
Request Object Data
  • "get" method in HTML calling page
  • ltform action"buya.aspx" methodgetgt
  • "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"

11
URL Encoding
  • ? after URL shows start of data
  • pairs of namevalue
  • (ampersands) between pairs
  • between separate words ( space)
  • special characters coded as nn ( is 2B)
  • http//www.company.com/search.asp?
  • ?custJabbaraddress23110thSt
  • example try doing a Yahoo search

12
Request Object Data - 2
  • "post" method in HTML calling page
  • ltform action"buya.aspx" methodpostgt
  • 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"

13
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

14
Using QueryString in an aspx File
  • can create the same effect sending from an aspx
    file as from a html file
  • Response.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

15
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

16
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)
  • lt x1 " " x2 " " etc.gt
  • same effect as Response.Write, in less space
  • less efficient (don't use lt a lot)

17
Response Methods - 2
  • redirecting to another page
  • Response.Redirect("buya.aspx")
  • stops processing on current page and goes to the
    other page
  • can go to external pages too

18
Server Transfer Method
  • can also use to redirect to another page, but
    only if it's on same server
  • Server.Transfer("buya.aspx")
  • doesn't change URL in browser address
  • comparison of Response.Redirect and
    Server.Transfer

19
Exercise Form Processing
  • use Dreamweaver to create a form that uses 8
    form elements/variations in its
    WindowsgtObjectsgtForms 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

20
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

21
Multiple Selection Data
  • can allow multiple selections in a list box on a
    form
  • ltselect size2 name"loc" multiplegt
  • ltoptiongtParislt/option gt
  • ltoptiongtSydneylt/option gt
  • ltoptiongtBuenos Aireslt/option gt
  • lt/selectgt
  • may send multiple items with same name ("loc" in
    this example)

22
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
Write a Comment
User Comments (0)
About PowerShow.com