CSCI 1302 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CSCI 1302

Description:

asp:Textbox id='op1' RunAt='server'/ asp:TextBox id='op2' RunAt='server' ... asp:Button id='Sum' text='=' OnClick='DoAdd' RunAt='server' ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 15
Provided by: jonpr
Category:
Tags: csci | onclick

less

Transcript and Presenter's Notes

Title: CSCI 1302


1
CSCI 1302
  • Client-Server Development

2
ASP.NET in C
  • Two sides
  • Code definition
  • HTML aspSOMETHING object
  • A simple calculator example

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

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

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

6
When 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

7
When 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

8
Putting 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

9
Two 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

10
Resultant Page (FINALLY)
11
The 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
12
Resultant Page (after submit)
13
The 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
14
FIN
Write a Comment
User Comments (0)
About PowerShow.com