1 / 114

VB Script, ASP, ASP Objects

VB Script, ASP, ASP Objects. Scripting Languages. An important use of Web browsers in electronic commerce is to enter information. Validation of input and calculations on the browser can be carried out via a type of computer programming known as scripting . Scripting Languages.

betrys
Télécharger la présentation

VB Script, ASP, ASP Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VB Script, ASP, ASP Objects

  2. Scripting Languages • An important use of Web browsers in electronic commerce is to enter information. • Validation of input and calculations on the browser can be carried out via a type of computer programming known as scripting.

  3. Scripting Languages • Scripting is similar to other types of computer programming in that it uses variables and statements to carry out a desired set of logical operations, but it is also different. • Instead of being executed as a compiled program, it is executed by another program, in our case the Web browser.

  4. Scripting Languages • Scripting languages are easier to work with than compiled languages. • A script takes longer to run than a compiled program since each instruction is being interpreted rather than being executed directly by the processor.

  5. Scripting Languages • The two most widely used scripting languages for working with Web pages are Javascript and VBScript. • Javascript uses a C-like syntax and can run on either Netscape or Internet Explorer browsers.

  6. Scripting Languages • VBScript is based on Visual Basic, but runs only on Internet Explorer. • Both Javascript and VBScript, when used on the browser, are termed client-side scripting since they are running on the Web client.

  7. Scripting Languages • VBScript is also widely used in the Active Server Page (ASP) approach to directing Microsoft Web server software that runs on Windows NT or 2000 operating systems. This is called server-side scripting.

  8. Scripts • Script is nothing but a set of commands that are written to perform a specific task • These commands are VBScript or JavaScript commands • There are two types of Scripts: • Client-Side Script : Runs On Browser (default : JavaScript) • Server-Side Script : Runs On Server (default : VBScript)

  9. Introduction VBScript • Small subset of VB language interpreted by Internet Explorer, IIS, Windows Scripting Host. • VBScript was first introduced for use with the Internet.

  10. VBScript language can be used as following: • Web Pages – client side VBScript code can be embedded in standard HTML, allowing Web Pages to contain application-like functionality. • Active Server Pages – Server-Side VBScript code can be used in ASP, allowing Web pages to be generated and altered before returning content to browser • The Windows Scripting Host- VBScript code can be run from the DOS command line like a batch file, allowing you to automate certain tasks.

  11. Differences between VBScript and Visual Basic

  12. Using VBScript • VBScript has only one type of variable—the Variant. • VBScript programs must be interpreted by other software, usually the Internet Explorer browser on the client side and Web server software on the server side. • In VBScript, we can write code to respond to the events, these code procedures are referred to as event handlers. • Since there is no easy-to-use IDE for VBScript that is readily available, it is convenient to use a texteditor like NotePad. • VBScript must be tightlyintegrated with the HTML.

  13. HTML • Web Pages use a number of tags (often begin & end tags) to display information on a Web Page • Page is created within <HTML>……</HTML> tags • Page is divided into the Head and Body created with <HEAD> ……. </HEAD> and <BODY> ….. </BODY> tags • A range of tags are available for font definition, table creation, form objects, web page links, page formatting etc. • Text can be typed directly in the Web Page for display

  14. Simple Web Page <HTML> <HEAD> </HEAD> <BODY> WCTM<br>Gurgaon </BODY> </HTML> [- Created in Notepad & saved as test1.htm - In Internet Explorer displays a web page with:

  15. HTML Form Tags • Forms have the tags <FORM>……</FORM> • If a form is used with buttons or text boxes (<INPUT> tags) e.g. <FORM name = “Form1”> <INPUT TYPE = “Text” NAME = “Text1”> <INPUT TYPE = “Button” NAME = “Button1” VALUE = “Submit”> </FORM> Then Form object properties such as the value of textbox Text1 are referred to as: Form1.Text1.Value

  16. VB Script • VBScript is entered between the tags <SCRIPT LANGUAGE = “VBScript”> ….. </SCRIPT> • Actions of a Submit Button are handled by the OnClick event as a subroutine Sub Button1_OnClick …….. End Sub

  17. Sample Application Application for doubling values entered (like in VBExercise1) Enter a value and it will be doubled Text Input Type (Text Box) Calculate Submit Input Type (Button)

  18. Sample Code <HTML> <HEAD> </HEAD> <BODY> Enter a value and it will be doubled: <br><br> <INPUT TYPE = "TEXT" NAME = "Text1" VALUE = 0><br> <INPUT TYPE = "TEXT" NAME = "Text2" VALUE = 0><br><br> <INPUT TYPE = "SUBMIT" NAME = "Button1" VALUE = "Calculate"><br> <SCRIPT LANGUAGE = "VBScript"> Sub Button1_OnClick Text2.Value = Text1.Value * 2 End Sub </SCRIPT> </BODY> </HTML>

  19. The <Script> Tag • All VBScript code must be enclosed in HTML script tags. <SCRIPT language=”VBScript”> ... </SCRIPT>

  20. Tools Used with VBScript • To use VBScript, you need to have the right tools. The following slides provide a brief rundown of some items that make working with VBScript easier.

  21. The VB Scripting Engine • The Script code is interpreted and executed by a scriptingengine. The scripting engine for VBScript is a file named VBSCRIPT.DLL, located in the \Windows\System directory. VBScript is installed with one of the applications that use it, such as Internet Explorer, Outlook, Internet Information Server, or the Windows Scripting Host.

  22. Host Application • The applications with which you can use VBScript are also known as hosts for VBScript. The most common hosts are Internet Explorer and Internet Information Server. Outlook also uses VBScript as its macro language. In addition, Microsoft recently introduced the Windows Scripting host, which allows you to run VBScript code from a regular Windows platform such as Windows NT or Windows 95.

  23. Text Editor • Many people who use VBScript with Web pages use a simple text editor to enter VBScript code because VBScript does not (yet) have its own integrated development environment. This means that all the great IDE features you are used to in regular VB are not available. You have to be careful that what you enter is spelled and formatted correctly. Some more advanced text editors, such as HomeSite, help you with VBScript code entry by providing automatic color-coding and toolbar buttons for commonly used statements. • Although a text editor as simple as Notepad will work

  24. Advanced Web Tools • ActiveX Control Pad. A free tool from Microsoft. It is really not that advanced, but it does provide a way to get class IDs for ActiveX controls. • Microsoft FrontPage. A Web page creation application. FrontPage includes a Script Wizard, which creates VBScript code for you and makes working with ActiveX controls and events easy. • Visual InterDev. Another Microsoft product, aimed more at developers of database-driven Web pages. It generates VBScript code for you. • Internet Client SDK. Software development kit that is available for downloading from Microsoft. It provides samples, documentation, and utilities for working with the Internet.

  25. Introduction to ASP • What is ASP? • ASP stands for Active Server Pages. • ASP is a program that runs inside IIS. • IIS stands for Internet Information Services. • ASP is Microsoft’s solution to building advanced Web sites.

  26. Introduction to ASP • How Does ASP Differ from HTML? • HTML file generates static pages, but ASP file generates dynamic pages. • HTML file has the extension .html/.htm, but ASP file has the extension .asp • When a browser sends a requests to the web server for an HTML file the server returns the file as it is to the browser, but when a browser sends a request to the web server for an ASP file, IIS passes the request to the ASP engine having a special program ASP.dll. This ASP file is processed line by line and executes the server side scripts(<% %>) in the file. Finally, the ASP file is returned to the browser as plain HTML.

  27. Introduction to ASP • Processing of an HTML Page Browser Request Web Server Memory-HTML file HTML File

  28. Introduction to ASP • Processing of an ASP Page Browser Request Web Server Processing Memory-ASP File HTML File

  29. Introduction to ASP • What can ASP do for you? • ASP file generates dynamic web pages displaying different contents for different users and at different times of the day. • Responds to user’s queries or data submitted from HTML forms. • Accesses any data or databases and return the results to a browser. • Customizes a Web page to make it more useful for individual users.

  30. Introduction to ASP ASP page can consists of the following: • HTML tags. • Scripting Language (JavaScript/VBScript). • ASP Built-In Objects. • ActiveX Components eg. : ADO – ActiveX Data Objects. So, ASP is a standard HTML file with extended additional features.

  31. ASP Syntax • The Basic Syntax Rule • An ASP file normally contains HTML tags, just as a standard HTML file. • In addition, an ASP file can contain server side scripts, surrounded by the delimiters <% and %>. Server side scripts are executed on the server, and can contain any expressions, statements, procedures, or operators that are valid for the scripting language you use.

  32. ASP Syntax • Scripts • Client-Side Script is embedded into the HTML file using tags: <scriptlanguage=JavaScript/VbScript> {JavaScript/Vbscript Code} </script> • Server-Side Script is embedded into the ASP file using tags: <script language=Vbscript/JavaScript RunAt=SERVER> {Vbscript/JavaScript Code} </Script> OR <%@ Language = VBScript/JavaScript %> <% {VBScript/JavaScript Code} %>

  33. ASP Syntax • Scripts • Difference Between using <Script> Tag and <% %> delimiters • <Script> tag is executed immediately no matter where it appears. • By using <Script> tag it is possible to mix multiple scripting languages within single ASP page. • Before using <% %> delimiters, this line of code is mandatory <%@ Language = VBScript/JavaScript %> which specifies the language being used.

  34. ASP Syntax • Example <%@ Language=VBScript %> <HTML> <HEAD> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript" RunAT="SERVER"> function sayhello() { response.write("Welcome") } </SCRIPT> <% For i=1 to 10 sayhello() Next %> </BODY> </HTML>

  35. ASP Variables • Variables • Variables are used to store information • This example demonstrates how to create a variable, assign a value to it, and insert the variable value into a text. <html> <body> <% Dim name name=“Tripti Arora" Response.Write("My name is: " & name) %> </body> </html>

  36. ASP Variables • Arrays • Arrays are used to store a series of related data items. • This example demonstrates how you can make an array that stores names. <%Dim name(5)name(0) = "Jan Egil"name(1) = "Tove"name(2) = "Hege"name(3) = "Stale"name(4) = "Kai Jim"name(5) = "Borge"For i = 0 to 5 Response.Write(name(i) & "<br />")Next%></body></html>

  37. ASP Variables • Session Variables • Session variables store information about one single user, and are available to all pages in one application. Common information stored in session variables are Username and UserID. To create a session variable, store it in a Session Object • Application Variables • Application variables are also available to all pages in one application. Application variables are used to hold information about all users in a specific application. To create an application variable, store it in an Application Object

  38. ASP Objects: • ASP has 7 built-in Objects: • Request • Response • Application • Session • Server • ObjectContext • Error

  39. ASP has 7 built-in Objects: ASP Objects Request Session Response Server Application ObjectContext Error

  40. These Objects have • Collection : An Object’s collections constitute different sets of keys and value pairs related to that object. • Properties : An Object’s properties can be set to specify the state of the object. • Methods : An Object’s methods determines the things one can do with the ASP Object. Eg : OBJECT : A Book. METHOD : Read a book. PROPERTIES : No. of pages. COLLECTION : Each page(key) has a particular text(value).

  41. Request Object Collections Properties QueryString Form ServerVariables TotalBytes

  42. ASP Forms and User Input • User Input • To get information from forms, you can use the Request Object • Example <form method="get" action="../pg.asp"> First Name: <input type="text" name="fname"><br> Last Name: <input type="text" name="lname"><br> <input type="submit" value="Send"> </form> • There are two ways to get form information: The Request.QueryString command and the Request.Form command.

  43. Request Object - Collections • Request.QueryString • This collection is used to retrieve the values of the variables in the HTTP query string. • Information sent from a form with the GET method is visible to everybody (in the address field) and the GET method limits the amount of information to send. • If a user typed “Bill" and "Gates" in the form example above, the url sent to the server would look like this: http://www.asp.com/pg.asp?fname=Bill&lname=Gates

  44. Request Object - Collections • Request.QueryString • The ASP file "pg.asp" contains the following script: <body> Welcome <% response.write(request.querystring("fname")) response.write("&nbsp;") response.write(request.querystring("lname")) %> </body> • The example above writes this into the body of a document: Welcome Bill Gates

  45. Request Object - Collections • Request.QueryString • The HTTP query string can be specified in the following ways: • By the values following the question mark (?) http://www.hotmail.com/hello.asp?username=Tripti • By using GET method of <Form> Tag. <Form Name=“form1” Action=“123.asp” Method=“GET”> … </form> • By using Action attribute of <Form> Tag. <Form Name=“form1” Action=“hello.asp?username=Tripti” Method=“POST”> … </form> • With the hyper link attribute < a href> Tag. <a href=“hello.asp? username=Tripti”>Hello</a>

  46. Request Object - Collections • Request.Form • It is used to retrieve the values of form elements posted to the HTTP request body, using the POST method of the <Form> Tag. • Information sent from a form with the POST method is invisible to others. • The POST method has no limits, you can send a large amount of information. • If a user typed "Bill" and "Gates" in the form example above, the url sent to the server would look like this: http://www.asp.com/pg.asp

  47. Request Object - Collections • Request.Form • The ASP file "pg.asp" contains the following script: <body> Welcome <% response.write(request.form("fname")) response.write("&nbsp;") response.write(request.form("lname")) %> </body> • The example above writes this into the body of a document: Welcome Bill Gates

  48. Request Object - Collections • Form Validation • The form input should be validated on the browser, by client side scripts. • Browser validation has a faster response time, and reduces the load on the server. • You should consider using server validation if the input from a form is inserted into a database. • A good way to validate the form on a server is to post the form into itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error.

  49. Request Object - Collections • ServerVariables Collection • It is used to retrieve the values of predetermined environment variables.These values originate when client requests the server. • Syntax: Request.ServerVariables (server environmentvariable)

  50. Request Object - Collections • Server Variables Collection Some of the Server Environment Variables: • Request_Method– returns GET or POST depending on how the request was made. • Query_String- returns the unparsed query string as in the request • Remote_Addr - returns the IP address of User • Logon_User - returns logon account of the user • ALL_HTTP- returns whole HTTP string • HTTP_User_Agent- returns the type of the client browser • HTTP_Accept_Language- determines which language is supported by the client’s browser • Path_Info - gives the full name of current file starting from the Web root directory. • Remote_Host - provides the visitor’s text URL

More Related