Pertemuan ke 13
PENGENALAN [Link]
Tentang ASP
Pengenalan ASP
HTML Intermediate
Formatting with Tables, Frames
Collecting information from the user using Forms
Pemrograman Web/TI/ AK045216/2 sks
Apa itu ASP ?
•Microsoft® Active Server Pages (ASP) merupakan server-side
scripting yang digunakan untuk membuat situs yang dinamis dan
aplikasi web yang interaktif.
•Sesuai prinsip server-side scripting, ASP juga merupakan halaman
HTML yang diisikan script-script yang diproses oleh web server
sebelum dikirim ke web browser.
•ASP dapat dikombinasikan dengan :
– Extensible Markup Language (XML)
– Component Object Model (COM)
– Hyper Text Markup Language (HTML)
Pemrograman Web/TI/ AK045216/2 sks
Perbandingan PHP dan ASP
Dengan persamaan sebagai server-side scripting, ASP dapat dibandingkan
dengan PHP dalam beberapa hal berikut ini (secara umum) :
ASP PHP
Sistem Operasi Microsoft Windows Unix, Linux
Web Server Personal Web Server (PWS) Apache Web Server
Internet Information Server (IIS)
Database Microsoft Access MySQL, Postgres,
Microsoft SQL Server Oracle, dll
Basic sintaks Visual Basic (VB) C / C++
Ekstensi file .asp .php
Pemrograman Web/TI/ AK045216/2 sks
Contoh script ASP - 1
•VBScript adalah bahasa scripting standar untuk membuat halaman ASP.
Pada contoh-contoh script berikut digunakan VBScript:
•Contoh 1 :
– Langkah pembuatan :
• Masukkan text ‘Hello World’ pada variabel FirstVar
• Buat tag awal HTML
• Gunakan <%FirstVar%> untuk menampilkan isi variabel FirstVar
• Akhiri tag HTML
– Script lengkap :
• <%@ Language=VBScript %>
• <html> <head> <title>Example 1</title> </head>
• <body>
• <% FirstVar = "Hello world!" %>
• <%=FirstVar%>
• </body>
• </html>
Pemrograman Web/TI/ AK045216/2 sks
Contoh script ASP - 2
•Contoh 2 :
<%@ Language=VBScript %>
<html> <head> <title>Example 2</title> </head>
<body>
<% FirstVar = "Hello world!" %>
<%FOR i=1 TO 10%> <%=FirstVar%>
<%NEXT%>
</body> </html>
•Contoh 3 :
<%@ Language=VBScript %>
<html> <head> <title>Example 4</title> </head> <body>
<%IF Hour(time)>18 OR Hour(time)<4 THEN%> Good Night
Everyone.
<%ELSE%> Good Morning Everyone. <%END IF%>
</body> </html>
Pemrograman Web/TI/ AK045216/2 sks
Perkembangan ASP
• Saat ASP ver 3.0 diluncurkan, programmer menemukan banyak
hal yang mempermudah proses pembuatan program. Ini
dikarenakan ASP telah diperkaya berbagai fungsi.
• Namun programmer masih menemukan masalah umum dalam
penggunaan ASP, yaitu ASP bersifat ‘code-oriented’. Yang
artinya segala hal yang ingin ‘dibuat’ haruslah ditulis dengan
kode-kode script.
• Microsoft mengeluarkan framework .NET pada Juli, 2000.
• Dengan adanya framework ini, programmer dapat membuat
program lebih ringkas dan cepat.
• Hal ini dikarenakan penggunaan framework yang dapat
mengurangi jumlah script yang dibuat oleh progammer.
Pemrograman Web/TI/ AK045216/2 sks
Perkembangan ASP
• Beberapa keunggulan framework .NET :
– Menggunakan model programming deklaratif
– Server kontrol hirarki dengan events.
– Class library yang cukup banyak.
– Support terhadap development tools, dari yang sederhana
(notepad) hingga Visual Studio .NET
• [Link] mulai diperkenalkan kepada programmer sebagai
pengganti penggunaan ASP klasik.
• [Link] versi 1.0 dan 1.1 diluncurkan untuk pertama kali dan
berharap saran dari pengguna untuk penyempurnaan [Link]
versi berikutnya.
Pemrograman Web/TI/ AK045216/2 sks
Generasi Pertama .NET
Client Logic Servers
Servers
Data,
Data,Hosts
Hosts
Biz Logic
Browsers
Browsers OS
Services
Penggunaan HTML oleh
programmer untuk membuat Aplikasi web berjalan sesuai prinsip
user interface aplikasi web. server-client. Pihak industri membuat
perangkat pembantu seperti database
Microsoft menyediakan
SQL Server™.
COM, IIS, Internet Explorer
Pemrograman Web/TI/ AK045216/2 sks
Generasi Kedua .NET
Biz
Biz Servers
Rich
Rich Tier Servers
Client TierLogic
Logic Data,
Data,Hosts
Hosts
ClientLogic
Logic
“Stateful”
Browsers OS
Browsers “Stateless” &
Services
“Geo-Scalable”
COM+ Services ditingkatkan. Internet
Explorer menyediakan DHTML untuk Pemisahan data dan
interaktif web bisnis proses
mempercepat proses
pembacaan aplikasi
Pemrograman Web/TI/ AK045216/2 sks
Platform .NET
Your Your
YourInternal
Visual
Visual YourApplication
Application Internal
Services
Studio
®
® .NET
Studio .NET and
andWeb
WebService
Service Services
Orchestration
Orchestration .NET
.NETEnterprise
Enterprise
Servers
Operations
Servers
Operations
Applications
Applications .NET
.NET
Using
UsingYour
Your Framework
Framework
Service
Service .NET
.NETFoundation
Foundation
Windows
Windows Services
Services
®
CE,
CE,2000,
2000,XP,
XP,.NET
®
.NET
End-User
End-User Internet Protocols
Clients 3 3rdParty
rd
PartyWeb
WebServices
Services
Clients SOAP “blue book”
HTTP, SMTP,Web/TI/
Pemrograman XML AK045216/2 sks
Framework .NET
Visual Basic® C++ C# JScript® …
Common Language Specification
Visual Studio .NET
[Link]: Web Services Windows
and Web Forms Forms
[Link]: Data and XML
Base Class Library
Common Language Runtime
Pemrograman Web/TI/ AK045216/2 sks
[Link] dan Visual Studio
[Link] dan Visual Studio® .NET didesain
untuk pembuatan web aplikasi
• Perancangan untuk web
aplikasi dan XMLWeb
services
• Drag and drop untuk
penggunaan tag HTML
• Penggunaan bahasa
pemrograman yang
terintegrasi
Pemrograman Web/TI/ AK045216/2 sks
Introduction [Link]
• Membangun class
programming dari
framework .NET
• Pengontrolan dan
pembangunan
infrastruktur
pengembangan web
apliksi
• Contoh web aplikasi :
Pemrograman Web/TI/ AK045216/2 sks
ASP Klasik
• Penggunaan model programming Kendala :
prosedural yang sederhana.
• Code readability
• Mengakses ke COM Objects :
• Coding overhead
– ADO
• PostBack complexity
– File system object
• Reuse
• Tanpa proses compile, hanya save
• Performance
(simpan).
• DLL locking
• Mendukung penggunaan berbagai
bahasa scripting. • Deployment
• Gabungan antara HTML dan kode- • Sessions
kode script. • Caching
• VBscript – leverage Visual Basic
skills
Pemrograman Web/TI/ AK045216/2 sks
Arsitektur [Link]
Compiled
Compiled .ASPX
.ASPX
Pemrograman Web/TI/ AK045216/2 sks
Kehandalan [Link]
• ASPX, ASP – side by side • Simplified form validation
• Simplified programming • Code behind pages
model • More powerful data access
• Simplified deployment • Web services
• Better performance • Better session management
• • No DLL locking
Caching
• No DLL registration
• Security
• Simplified configuration
• Powerful controls
• Pagelets
• Simplified browser support
Pemrograman Web/TI/ AK045216/2 sks
Page Development
Separation of Code from Content
• Pemisahan kode-kode script terhadap konten sehingga designer
dan programmer dapat bekerja lebih independen
ASP [Link]
Single file Separate files
code
<tags> <tags> code
[Link] [Link] [Link]
Pemrograman Web/TI/ AK045216/2 sks
Page Development
Code-
Parse ASPX Generate
behind
Dynamic Engine class
file
Compilation
Request ASPX Gen’d
Instantiate
ASPX
File Page
Request File Class
File
Response
Page
Response Class
Instantiate, process
and render
Pemrograman Web/TI/ AK045216/2 sks
Demonstration 1
ASP vs. [Link]
Data-Driven ASP
Data-Driven [Link]
Comparison
Pemrograman Web/TI/ AK045216/2 sks
Server Controls
Simplify Common Tasks
• Simplify common tasks
– Forms
– Tables
– Data display
– Calendar
– Ad rotator
• Server-side programming model
• Automatic browser compatibility
• Less code, less complexity
• Extensible
Pemrograman Web/TI/ AK045216/2 sks
Server Controls
HTML and Server Controls
<div id="MyDiv" runat="server"/>
<asp:TextBox id="txtUserName" runat="Server"/>
<asp:button type="submit" OnClick="SubmitBtn_Click"
runat="server"/>
ID – uniquely identifies control
Runat – enables server-side processing
OnClick – identifies server-side event handler
Pemrograman Web/TI/ AK045216/2 sks
Server Controls
Forms
<script language="C#" runat=server>
void SubmitBtn_Click(Object sender, EventArgs e) {
[Link] (“Hello” + [Link]);
}
</script>
PostBack
– Server-side object automatically populated from client-side
controls
Pemrograman Web/TI/ AK045216/2 sks
Server Controls
Browser Support
Targets client on the fly
<asp:textbox ForeColor=“red”/>
– Style
– Font
Validation
– Client-side
– Server-side
Pemrograman Web/TI/ AK045216/2 sks
Demonstration 2
Server Controls Walk-Through
Programming Model
Syntax
Pemrograman Web/TI/ AK045216/2 sks
Server Controls
Validation
Without code
– Required field
– Within range
– Two fields equal (password)
– Regular expressions
– Validation error messages
With code, but simplified
– Custom validation
Pemrograman Web/TI/ AK045216/2 sks
Demonstration 3
Validation
Required Field
Validation Summary
Pemrograman Web/TI/ AK045216/2 sks
Data Controls
Bind to many data sources
– Collections
• Array
• HashTable
– [Link]
• DataReader
• DataSet
– XML
Pemrograman Web/TI/ AK045216/2 sks
Data Controls
[Link]
• Connection
• Command
• DataReader
• DataSet
• DataAdapter
• DataView
Pemrograman Web/TI/ AK045216/2 sks
Data Controls
[Link]
DataSet
Database
Authors
Connection Authors
Authors
DataAdapter
Select … from Authors
Pemrograman Web/TI/ AK045216/2 sks
Data Controls
[Link]
DataSet
Database
Authors
Connection Publishers
Publishers
DataAdapter
Publishers
Select … from
Publishers
Pemrograman Web/TI/ AK045216/2 sks
Data Controls
[Link]
DataSet
Authors DataGrid
Repeater
Publishers
DataList
DataView
Pemrograman Web/TI/ AK045216/2 sks
Data Controls
DataGrid
• Displays data as a table
• Control over
– Alternate item
– Header
– Footer
– Colors, font, borders, etc.
– Paging
• Updateable
• Item as row
Pemrograman Web/TI/ AK045216/2 sks
Data Controls
Repeater
• List format
• No default output
• More control
• More complexity
• Item as row
• Not updateable
Pemrograman Web/TI/ AK045216/2 sks
Data Controls
DataList
• Directional rendering
• Good for columns
• Item as cell
• Alternate item
• Updateable
Pemrograman Web/TI/ AK045216/2 sks