mark dixon, socce soft 131page 1 23 – modular design in asp

Post on 19-Dec-2015

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Mark Dixon, SoCCE SOFT 131 Page 1

23 – Modular Design in ASP

Mark Dixon, SoCCE SOFT 131 Page 2

Session Aims & Objectives• Aims

– Highlight modular design techniques in ASP

• Objectives,by end of this week’s sessions, you should be able to:

– Use procedures, functions, and parameters in ASP

Mark Dixon, SoCCE SOFT 131 Page 3

Example: People DatabasePersonPersonID

Surname

Forenames

Gender

Phone eMail

1 Dixon Mark Yes 01752 232556

mark.dixon@plymouth.ac.uk

2 Smith John Yes 01752 111111

john.smith@john.smith.ac.uk

3 Jones Sally No 01752 888888

sally.jones@sally.jones.com

4 Bloggs Fred Yes 01752 123123

fred.bloggs@aaaaaa.com

5 Anderson Genny No 01752 987987

genny@bbbb.cccc.com

6 Smith Bob Yes 01752 898898

bob.smith@bob-smith.com

Mark Dixon, SoCCE SOFT 131 Page 4

Example: People (design)

Mark Dixon, SoCCE SOFT 131 Page 5

Example: People (code)

<script runat="server" src="_People.vbs"></script>

<html> <head><title>People</title></head> <body> <% DisplayMenu Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(PersonName(rs) & "<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body></html>

Const cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\People.mdb;Persist Security Info=False"Const adOpenDynamic = 3

Sub DisplayMenu() Response.Write("<center>") Response.Write("<a href='People.aspx'>People</a> ") Response.Write("<a href='Person.aspx'>Person</a>") Response.Write("</center><br><br>")End Sub

Function PersonName(r) PersonName = r.Fields("Forenames").Value & " " & r.Fields("Surname").ValueEnd Function

<script runat="server" src="_People.vbs"></script>

<html> <head><title>Person Page</title></head> <body> <% DisplayMenu Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs, adOpenDynamic) If Session("curID") <> "" Then rs.Find("[ID] = " & Session("curID")) If Request.Form("btnPrev") <> "" Then rs.MovePrevious() ElseIf Request.Form("btnNext") <> "" Then rs.MoveNext() End If End If Session("curID") = CStr(rs.Fields("ID").Value) Response.Write(PersonName(rs) & "<br>") rs.Close() rs = Nothing %> <form action="Person.aspx" method="post"> <input name="btnPrev" type="submit" value="Previous" /> <input name="btnNext" type="submit" value="Next" /> </form> </body></html>

Mark Dixon, SoCCE SOFT 131 Page 6

Adding VB Script file• Right click project

• click 'add new item'

Mark Dixon, SoCCE SOFT 131 Page 7

Tutorial Exercise: People• Task 1: Use module (files) and procedures

in your assignment.

top related