21
CSCI 6962: Server-side Design and Programming Introduction to Active Server Pages

CSCI 6962: Server-side Design and Programming

  • Upload
    adeola

  • View
    43

  • Download
    0

Embed Size (px)

DESCRIPTION

CSCI 6962: Server-side Design and Programming. Introduction to the ASP User Interface. Active Server Pages. Active Server Page approach: Create “form” which is translated to html. Active Server Pages. Server-side code manipulates “form elements” Subroutine called when page submitted - PowerPoint PPT Presentation

Citation preview

Page 1: CSCI 6962:  Server-side Design and  Programming

CSCI 6962: Server-side Design and Programming

Introduction to Active Server Pages

Page 2: CSCI 6962:  Server-side Design and  Programming

2

Active Server Pages• Active Server Page approach:

Create “form” which is translated to html

Page 3: CSCI 6962:  Server-side Design and  Programming

3

Active Server Pages• Server-side code manipulates “form elements” – Subroutine called when page submitted– Data read from elements (actually request string)– Used to set value of other elements

Page 4: CSCI 6962:  Server-side Design and  Programming

4

Active Server Pages• Resulting form translated to response page

Page 5: CSCI 6962:  Server-side Design and  Programming

ASP/IIS Architecture

• IIS routes request to ASP.NET if .aspx file requested• ASP.NET loads requested .aspx file, runs code, and converts

resulting form to html file

Page 6: CSCI 6962:  Server-side Design and  Programming

Creating a New Web Site• Choose File

New Web Site• Choose “ASP.NET

Empty Web Site”– Can select either

Visual Basic or Visual C#

– Can set name/location of site at bottom

Page 7: CSCI 6962:  Server-side Design and  Programming

Adding a Web Form• Solution Explorer contains files related

to application– Initially Web.config (like web.xml in JSF)

• Right-click site name in Solution Explorer Add New Item

Page 8: CSCI 6962:  Server-side Design and  Programming

Ways to View Page• Source: Html source code (can insert html tages)• Design: WYSIWYG mode showing corresponding page• Split: Both simultaneously

Page 9: CSCI 6962:  Server-side Design and  Programming

Viewing the Web Page

• Simplest method: Cntrl-F5 • Runs page in default browser

Page 10: CSCI 6962:  Server-side Design and  Programming

Toolbox

• Toolbox on LHS lets you drag components onto page– Similar to VB, VC#– Components not created programmatically

Page 11: CSCI 6962:  Server-side Design and  Programming

Example: Adding a Button

• Click on the Button option and drag it onto the screen• Drag to desired location

– Design or Split mode– Within defined area

of page

Page 12: CSCI 6962:  Server-side Design and  Programming

Properties Window

• Visual components commonly edited with Properties box on RHS– Example: Text property controls text displayed on button

Page 13: CSCI 6962:  Server-side Design and  Programming

Setting Component ID

• Visual components referred to using ID property – Most important property to set (like name in JSP)– Allows code to get/set property values

Page 14: CSCI 6962:  Server-side Design and  Programming

ASP and Dynamic Pages

• Code used to manipulate ASP site– Code activated by event (such as submit button

being pressed)– Code can read properties of visual controls– Code can modify properties of other visual

controls to change page

Page 15: CSCI 6962:  Server-side Design and  Programming

“Hello World” Example

• Textbox for name – ID = nameBox

• Label for greeting – ID = greetLabel, Text = “”

• Button to activate code – ID = helloButton (not strictly necessary, but good practice)

Page 16: CSCI 6962:  Server-side Design and  Programming

Accessing Code Window

• Double-click on window shows code associated with events (“code behind”)– .cs file associated with all events– Page_Load = code executed when page loaded– helloButton_Click executed when button pressed

Page 17: CSCI 6962:  Server-side Design and  Programming

Adding Code• Code added to helloButton_Click executed when button

pressed

Get the Text property of the nameBox

Append that name to the rest of the string using “+”

Write that string into the Text property of the greetLabel

Page 18: CSCI 6962:  Server-side Design and  Programming

Viewing the Result

• Run with Cntrl-F5, enter a name and press the button• The code is executed:– String read from Text property of nameBox– String written to Text property of greetLabel

Page 19: CSCI 6962:  Server-side Design and  Programming

Default Post Back Mode

• By default, same page requested from server• All component values automatically echoed in page

sent back as response– Similar to JSF

Page 20: CSCI 6962:  Server-side Design and  Programming

How Does This Work?

• At client side, these components displayed as corresponding html

• Event causes page to be submitted to server– Form data included in request

Page 21: CSCI 6962:  Server-side Design and  Programming

How Does This Work?

• By default, same page requested (“postback”)

• Implemented as Visual Basic/C# form at server side• Form data from request written into the properties of the form

elements– Parameter value for text element Text property of TextBox