Title: 2314 Programming Language Concepts
12314 Programming Language Concepts
- Test 2 Grades
- Introduction to ASP.NET
2Test 2 Grades
Average 75.7 Pass Rate 60
3Grade Differential (Test 1 Test 2)
4Sample Answers
- Progression from Win32 API (system calls) to MFC
(macros) to .NET (drag-drop/WYSISYG) - Most of the time was spent in design
- Data structure (array of records) and appropriate
methods/algorithms and interface - GUI vs. console app (little change to core)
- Paint and onClick methods
- Details and specific information (not vague)
5Introduction to Client-Server Programming
6Client-Server Cycle
- Client requests page
- Client formats an HTTP request
- HTTP Example Server Side
- Server responds
- Finds requested file
- Formulates response and sends to client
- Header
- Fields (informs client)
- Body (content)
7ASP
- Implemented via asp.dll (ISAPI)
- Process ASP files before sending to client
- Uses VBScript or JavaScript
- Embed code data (BAD!)
- Mixes content with code
- Optionally include
8ASP (cont)
- Limits access to controls
- Ad Rotator
- FileSystemObject
- ADO (ActiveX Data Object) DB Connections
- Can purchase 3rd party components or develop COM
wrappers to access Win32 API
9ASP.NET
- Implemented via ISAPI aspnet_isapi.dll
- Processes ASPX files before sending to client
- Uses the CLR (common language runtime)
- Can program ASP.NET in ANY CLR language (C
VB.NET most popular)
10ASP.NET
- Full access to the .NET Class Library (immense!)
- Session information shared across multiple
servers (server farm scalability) - Configuration easy via .config files
11ASP.NET in C
- Two sides
- Code definition
- HTML aspSOMETHING object
- A simple calculator example
12The Form
Absolutely, positively NEVERforget the RunAt
attribute!
- ltHTMLgt
- ltBODYgt
- ltform RunAt"server"gt
- ltaspTextbox id"op1" RunAt"server"/gt
- ltaspTextBox id"op2" RunAt"server"/gt
- ltaspButton id"Sum" text""
OnClick"DoAdd" RunAt"server"/gt - ltaspLabel id"Result" RunAt"server"/gt
- lt/formgt
- lt/BODYgt
- lt/HTMLgt
13The Code
- ltSCRIPT Language"C" RunAt"server"gt
- void DoAdd (Object sender, EventArgs e)
-
- int i Convert.ToInt32(op1.Text)
- int j Convert.ToInt32(op2.Text)
- int r i j
- Result.Text r.ToString()
-
- lt/SCRIPTgt
14Two Options
- Place the HTML and SCRIPT in one file with an
ASPX extension - Place the HTML in a file with an ASPX extension
- Place the code in a file with a .cs extension
- Add a reference to the code file in the ASPX file
- lt_at_ Page language"c" src"SOURCE.cs" gt
15When an ASPX File is Requested
- Client sends a request to server for add.aspx
- Server locates file realizes its extension
- Sends it to the appropriate ISAPI processor
- Processes file, replacing references to asp
object controls with HTML 4.01 - Only compiles file if it has changed since last
referenced (JIT) - Uses cache copy of file if possible (improves
performance) - Executes Load and Init functions (if any)
- Adds hidden state information
- Client only sees HTML, no source code at all
- Serves the result to client
- Client receives HTML and renders it in browser
16Client-Server Request/Response Process
17When an Event is Generated
- Callback to server
- Function is executed
- Possible changes to HTML
- Server responds with HTML 4.01 results
- Does require round-trip
- Usually efficient b/c of small data in transit
18Putting it Together (calc.aspx)
- ltHTMLgt
- ltBODYgt
- ltform RunAt"server"gt
- ltaspTextbox id"op1" RunAt"server"/gt
- ltaspTextBox id"op2" RunAt"server"/gt
- ltaspButton id"Sum" text""
OnClick"DoAdd" RunAt"server"/gt - ltaspLabel id"Result" RunAt"server"/gt
- lt/formgt
- lt/BODYgt
- ltSCRIPT Language"C" RunAt"server"gt
- void DoAdd (Object sender, EventArgs e)
-
- int i Convert.ToInt32(op1.Text)
- int j Convert.ToInt32(op2.Text)
- int r i j
- Result.Text r.ToString()
-
- lt/SCRIPTgt
19Two More Tasks
- Create a virtual directory in IIS pointing to the
directory that contains calc.aspx - Remember all dynamic pages MUST be viewed in a
browser (you cant just double-click them in
explorer) - Allows you to view the page in your browser
- Run the permissions wizard on this new virtual
directory - Allows the ASP.NET page to be processed
- Get an error (cannot display page) if you
forget this step
20Resultant Page (FINALLY)
21The HTML Source
- ltHTMLgt
- ltBODYgt
- ltform name"_ctl0" method"post"
action"calc.aspx" id"_ctl0"gt - ltinput type"hidden" name"__VIEWSTATE"value"dDwt
MTM3MDk5MDcwNDs7PvmsttsAST3BC5jicR6AndD0Ow" /gt - ltinput name"op1" type"text" id"op1" /gt
- ltinput name"op2" type"text" id"op2" /gt
- ltinput type"submit" name"Sum" value""
id"Sum" /gt - ltspan id"Result"gtlt/spangt
- lt/formgt
- lt/BODYgt
-
- lt/HTMLgt
Auto-generated material is highlighted
22Resultant Page (after submit)
23The HTML Source (after submit)
- ltHTMLgt
- ltBODYgt
- ltform name"_ctl0" method"post"
action"calc.aspx" id"_ctl0"gt - ltinput type"hidden" name"__VIEWSTATE"
value"dDwtMTM3MDk5MDcwNDt0PDtsPGk8MT47PjtsPHQ8O2w
8aTw3PjsO2w8dDxwPHA8bDxUZXh0Oz47bDwxMjsPjsOzsO
z4Oz4Oz6pyFGIUcsfxJmwPKg9fE2//Jx4Q" /gt - ltinput name"op1" type"text" value"5"
id"op1" /gt - ltinput name"op2" type"text" value"7"
id"op2" /gt - ltinput type"submit" name"Sum" value""
id"Sum" /gt - ltspan id"Result"gt12lt/spangt
- lt/formgt
- lt/BODYgt
-
- lt/HTMLgt
Modified material is highlighted