Pertemuan 3 Server Side Scripting (ASP & ASP.Net) Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.

Slides:



Advertisements
Similar presentations
DT228/3 Web Development WWW and Client server model.
Advertisements

Session 13 Active Server Pages (ASP) Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Languages for Dynamic Web Documents
Building Applications using ASP.NET and C# / Session 1 / 1 of 21 Session 1.
Asp.NET Core Vaidation Controls. Slide 2 ASP.NET Validation Controls (Introduction) The ASP.NET validation controls can be used to validate data on the.
1 Chapter 12 Working With Access 2000 on the Internet.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
15 Chapter 15 Web Database Development Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
1 Web Servers (IIS and Apache) Outline 9.1 Introduction 9.2 HTTP Request Types 9.3 System Architecture 9.4 Client-Side Scripting versus Server-Side Scripting.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Web Servers1-1 Web Servers Xingquan (Hill) Zhu
Introduction to ASP.NET. Prehistory of ASP.NET Original Internet – text based WWW – static graphical content  HTML (client-side) Need for interactive.
1 Web Server Concepts Dr. Awad Khalil Computer Science Department AUC.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Module 7: Validating User Input.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Server-side Scripting Powering the webs favourite services.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 33 - Active Server Pages (ASP) Outline 33.1 Introduction 33.2 How Active Server Pages Work 33.3.
3/8/00asp00 1 Active Server Pages from Microsoft Nancy McCracken Northeast Parallel Architectures Center at Syracuse.
Active Server Pages (ASP) 1. 2 Introduction Active Server Pages (ASP) –Server-side text file –Processed in response to client request –Pages are processed.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design.
ASP.Net Web Applications. Characteristics of a typical data driven web application Web Server HTML Graphics Active-X Java Applets HTTP Request ADO / JDBC.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 21 - Web Servers (IIS, PWS and Apache) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Introducing ASP.NET 2.0. Internet Technologies WWW Architecture Web Server Client Server Request Response Network HTTP TCP/IP PC/Mac/Unix + Browser (IE,
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Module 4: Creating a Microsoft ASP.NET Web Form. Overview Creating Web Forms Using Server Controls.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 26 – Active Server Pages (ASP) Outline 26.1Introduction 26.2How Active Server Pages Work.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
BlackBerry Applications using Microsoft Visual Studio and Database Handling.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Session 6: Validating User Input. Outline Overview of User Input Validation Client-Side and Server-Side Validation ASP.NET Validation Controls Using Validation.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 User Input Validating.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Introduction and Principles Web Server Scripting.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
ASP.NET Part I Dr. Awad Khalil Computer Science Department AUC.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 33 - Active Server Pages (ASP)
PHP / MySQL Introduction
ASP.NET Module Subtitle.
Presentation transcript:

Pertemuan 3 Server Side Scripting (ASP & ASP.Net) Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2

Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Menjelaskan konsep server side scripting Membuat program menggunakan ASP & ASP.Net

Material Outline Mengenal Server side scripting Pemrograman dasar ASP & ASP.Net Koneksi ke database

Server Side Scripting Server Side Scripting is script that execute in web server (IIS, Apache Web Server, etc) Server Side Scripting very useful if require validation against database, server processing and security.

Introduction to ASP ASP (Active Server Pages) is server side scripting from Microsoft that usually uses Internet Information Services (IIS) as web server. Active Server Pages (ASP) –Processed in response to client request –ASP file contains HTML and scripting code –VBScript de facto language for ASP scripting Other languages can be used –JavaScript –.asp file extension –Microsoft-developed technology –Send dynamic Web content HTML DHTML ActiveX controls Client-side scripts Java applets

How ASP Work Client sends request –Server receives request and directs it to ASP –ASP processes, then returns result to client HTTP request types –Request methods GET –Gets (retrieves) information from server –Retrieve HTML document or image POST –Posts (sends) data to server –Send info from HTML form »Client-entered data »Info to search Internet »Query for a database »Authentication info

How ASP Work Browsers often cache Web pages –Cache: save on disk –Typically do not cache POST response Next POST request may not return same result Client requests ASP file –Parsed (top to bottom) by ActiveX component asp.dll ActiveX component: server-side ActiveX control that usually does not have GUI Code executed as statement –Specifies scripting language –If not used, VBScript assumed As interpreted, HTML (plus client-side scripts) sent to client –Parsed each time requested –Web server must support ASP by providing component such as asp.dll

Client Side VS Server Side Client-side scripting –Used for: Validation Interactivity Enhancing Web page with ActiveX controls Dynamic HTML Java applets Accessing browser –Browser-dependent Scripting language must be supported by browser or scripting host –Viewable on client Protecting source code difficult

Client Side Vs Server Side Server-side scripting –Reside on server  more flexibility Database access –Usually generate custom response for client –Access to ActiveX server components Extend scripting language functionality –Run exclusively on server  cross-platform issues not a concern –Not visible to client Only HTML + client-side scripts sent to client

ASP Example Scripting delimiters – –Indicate code is to be executed on server, not –Specify scripting language (default VBScript) – Each time page refreshed, server loads and interprets ASP

 2000 Deitel & Associates, Inc. All rights reserved. Outline 1.1Specify VBScript as scripting language 1.2Use Option Explicit to indicate variables be explicitly declared by programmer 1.3Use META tag to set refresh interval Time gets current time on server (hh:mm:ss) Short for A Simple ASP Example Simple ASP Example

 2000 Deitel & Associates, Inc. All rights reserved. Output from a simple Active Server Page

Server Side ActiveX Component Server-side ActiveX components –Typically do not have GUI –If scripting language for ASP not support certain feature, create ActiveX Server component Visual C++, Visual Basic, Delphi, etc. –Usually execute faster than scripting language equivalents –Executed on server Client does not need to support ActiveX technologies

 2000 Deitel & Associates, Inc. All rights reserved. Some server-side ActiveX components included with IIS and PWS

 2000 Deitel & Associates, Inc. All rights reserved. Outline 1.1Create instance of AdRotator component 1.2Call Response object’s Write method to send advertisement to client AdRotator Example AdRotator Example 13 14<% 15 ' Declare flagChanger 16 Dim flagChanger ' Create an AdRotator object 19 Set flagChanger = Server.CreateObject( "MSWC.AdRotator" ) ' Use config.txt to send an advertisement to the client 22 Call Response.Write( _ 23 flagChanger.GetAdvertisement( "config.txt" ) ) 24%> 25 26

 2000 Deitel & Associates, Inc. All rights reserved. Outline config.txt 1.Header includes image HEIGHT, image WIDTH and image BORDER width Asterisk separates header from advertisements Image location Destination URL ALT tag Percentage of time image appears 27WIDTH 54 28HEIGHT 36 29BORDER 1 30* 31/images/us.gif 32http:// 33United States Information /images/france.gif 36http:// 37France Information /images/germany.gif 40http:// 41Germany Information /images/italy.gif 44http:// 45Italy Information /images/spain.gif 48http:// 49Spain Information 5020

 2000 Deitel & Associates, Inc. All rights reserved. Demonstrating the AdRotator ActiveX component

File System Object File System Objects (FSOs) –Manipulate files, directories and drives –Read and write text –In Microsoft Scripting Runtime Library –5 FSO types: FileSystemObject –Interact with File s, Folder s and Drive s File –Manipulate File s of any type Folder –Manipulate Folder s (i.e, directories) Drive –Gather info about Drive s (local or remote) TextStream –Read and write text files

File System Object OpenTextFile(filename, code, create) –filename - file to open –code 8 - open for appending 1 - open for reading 2 - open for writing –create? - if true, creates a new file if does not exist

 2000 Deitel & Associates, Inc. All rights reserved. FileSystemObject methods

 2000 Deitel & Associates, Inc. All rights reserved. Some common File properties and methods

 2000 Deitel & Associates, Inc. All rights reserved. Some Folder properties and methods

 2000 Deitel & Associates, Inc. All rights reserved. Drive properties

Quering Data <% 'Declare Variables Dim dcnDB'As ADODB.Connection Dim rsDB'As ADODB.Recordset Dim sqlQuery'As String 'Find path of database file filePath = Server.MapPath("depkeu.MDB") 'Open Database Connection Set dcnDB = Server.CreateObject("ADODB.Connection") 'dcnDB.Open "DBName" - This is for an ODBC Datasource (if set up) or ' use the below code for opening a Access 2000 DB dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&filePath dcnDB.Open 'Query and create recordset sqlQuery = "SELECT * FROM Students ORDER BY LastName,FirstName" Set rsDB = Server.CreateObject("ADODB.Recordset") Set rsDB = dcnDB.Execute(sqlQuery) %>

Quering Data ">Update "> Delete <% rsDB.MoveNext Loop %>

Updating Data <% 'Declare Variables Dim dcnDB'As ADODB.Connection Dim rsDB'As ADODB.Recordset Dim sqlQuery'As String Dim sqlUpdate'As String Dim filePath'As String 'Find path of database file filePath = Server.MapPath("depkeu.mdb") 'Open Database Connection Set dcnDB = Server.CreateObject("ADODB.Connection") 'dcnDB.Open "DBName" - This is for an ODBC Datasource (if set up) or ' use the below code for opening a Access 2000 DB dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&filePath dcnDB.Open

'Check for action If Request.Form("action") = "Update" Then 'Create SQL UPDATE statement from form fields sqlUpdate = "UPDATE Students " _ & "Set FirstName = '" & Request.Form("FirstName") & "'," _ & "LastName = '" & Request.Form("LastName") & "' " _ & "WHERE StudentID = '" & Request.Form("StudentID") & "'" 'Execute the query dcnDB.Execute(sqlUpdate) 'Notify action taken Response.Write "Record Updated " End If 'Check for StudentID in URL Path If Request("StudentID") <> "" Then 'Create SQL String sqlQuery = "SELECT * FROM Students WHERE StudentID = '" & Request("StudentID") & "'" 'Query the database and create a recordset Set rsDB = Server.CreateObject("ADODB.Recordset") Set rsDB = dcnDB.Execute(sqlQuery) End If %>

ASP.NET New version of ASP Using.NET CLR.aspx extension ASP.Net is part of Visual Studio.Net

Visual Studio.Net IDE

ASP.NET Code Untitled Page

Toolbox

Simple Form

ASP.Net Code Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = "Helo " & DropDownList1.Text & ", Selamat Belajar ASP.Net" End Sub End Class

Result

Validation in ASP.Net ASP.NET provides validation controls to: Compare values Compare to a custom formula Compare to a range Compare to a regular expression pattern Require user input Summarize the validation controls on a page

Adding Validation Controls to a Web Form 1. Add a validation control 2. Select the input control to validate 3. Set validation properties <asp:Type_of_Validator id="Validator_id" runat="server" ControlToValidate="txtName" ErrorMessage="Message_for_error_summary" Display="static|dynamic|none" Text="Text_to_display_by_input_control"> <asp:Type_of_Validator id="Validator_id" runat="server" ControlToValidate="txtName" ErrorMessage="Message_for_error_summary" Display="static|dynamic|none" Text="Text_to_display_by_input_control">

Positioning Validation Controls on a Web Form Create error messages Select display mode Static Dynamic

Combining Validation Controls Can have multiple validation controls on a single input control Only the RequiredFieldValidator checks empty controls

Input Validation Controls RequiredFieldValidator InitialValue CompareValidator ValueToCompare or ControlToCompare Type Operator RangeValidator MinimumValue MaximumValue Type Code Examples

Using the RegularExpressionValidator Control Used when input must conform to a pre-defined pattern Visual Studio.NET includes patterns for: Telephone numbers Postal codes addresses <asp:RegularExpressionValidator … ControlToValidate="US_PhoneNumber"… ValidationExpression=" ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4} " …>* <asp:RegularExpressionValidator … ControlToValidate="US_PhoneNumber"… ValidationExpression=" ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4} " …>*

Connecting to Database Namespace used: System.Data.SqlClient and System.Data. Classes used: SqlConnection, SqlDataAdapter and SqlCommand.

Connecting to database dim cn as sqlConnection cn= new SqlConection (“server=localhost;uid=“ &username.text & “;pwd=“&pass.value &”;database=pubs;”) try ‘open connection cn.open … catch sx as sqlException … end try cn.close

Using Templates with List-Bound Controls Displaying Data in the Repeater and DataList Controls Using Templates Demonstration: Using a DataList Control

Displaying Data in the Repeater and DataList Controls Create the control and bind it to a DataSet Set custom properties Autoformat Columns (horizontal vs. vertical columns) Display data in templates

Using Templates FooterTemplate HeaderTemplate ItemTemplate SeparatorTemplate AlternatingItemT emplate