1 / 22

CIS 451: ASP.NET Objects

Learn the basics of object-oriented programming in ASP.NET, including the concept of objects, properties, methods, and events. Explore other important object concepts and understand how to use Request and Response objects in ASP.NET.

holmes-vang
Download Presentation

CIS 451: ASP.NET Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  11. 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

  12. 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"

  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) • <%= x1 [& " " & x2 [& " " & etc.]%> • same effect as Response.Write, in less space • less efficient (don't use <%= 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 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

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

  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

More Related