Thursday, 19 March 2015

ASP Basic Tutorial

ASP

Active Server Pages

ASP is the server side scripting language. Web application can be created. Virtual directory must be created which is like web server where files are stored in this directory.

Creation of Virtual Directory

1.            Go to My Computer à Interpub folder à wwwroot folder.
2.            Go to File Menu à New à Folder à Give any name to the new folder.
3.            Select it and right click.
4.            Select Properties option à Web Sharing tab and à Click Share this folder.
5.            Select the Read, Execute and Script check boxes and give Ok button.

Important Points
1.            ASP will run in IIS (Internet Information Server).
2.            It needs PWS (Personal Web Server) which is installed in Win95 / Win98.
3.            In Windows NT, it is installed in Windows NT 4.0 Option Pack.
4.            ASP is developed by Microsoft Corporation.
5.            IIS will run only Windows NT 4.0 Option Pack.
6.            PWS will run only in Win95 / Win98.

ASP Rules

1.            ASP coding is written in Notepad.
2.            It also contains HTML tags and VB Scripting statements.
3.            ASP file contains Server Script surrounded by the delimiters (<%….%>).
4.            ASP coding are case sensitive.
5.            Starting tag for ASP is <% @Language=”VBSCRIPT” %>.
6.            For html and VB scripting files must have .html as file extension.
7.            ASP file must have .asp as file extension.
8.            ASP files are executed in Browser (Netscape Navigator or Microsoft Internet Explorer).

Calling ASP file in HTML file

Syntax:

Attributes

Name=”form name”             à To give the variable name to the form.
Action=”asp file location”    à To give the asp file stored location or path.
Method=”post/get”                à To give the type of method for the data to pass.
Post method  à To pass large packs or data.
Get method   à To pass small pack or data.

ASP file location Information

“http://personal web server/virtual directory name/file name.asp or .html”
http (Hyper Text Transfer Protocol)
HTML file à Client                                      ASP file à Web Server

Declaration Statement

Syntax:
Dim ,,…
To declare the variables to store values.

ASP Built-in Objects

1.            Response
2.            Request
3.            Server

1.         Response Object
Syntax:
<% response.write(“message or html tags” & ) %>
To print any message or value of the variable.

2.            Request Object
Syntax:
<% asp variable name = request.form(“html variable name”) %>
To retrieve the values from the client and pass it to web server.

3.         Server Object
Syntax:
<% server.method(“Program ID”) %>
method= CreateObject à Creates an instance of a server component.
Program ID à Specify the type of the object to create.

Programs

File Name 1: Msg.asp

<% @Language="vbscript" %>
<%
            response.write("
Welcome to ASP Page
")
            response.write("Active Server Page")
%>
To execute in browser : http://localhost/612/msg.asp

File Name 2: headloop.asp


Program to print the heading in different levels

<%
            Dim a
            for a = 1 to 6
                  response.write(" Header Levels " & a & "")
            next
%>
html>

File Name 3: Proc1.asp

<%
            sub proc(a,b)
                  response.write(a*b)
            end sub
%>
           

Result of the Calculation = <% call proc(5,5) %>



File Name 4(a):        Test1.html

ASP Pages

Enter name :

File Name 4(b):        Test1.asp

<%@ language="vbscript" %>
<%
            s=request.form("t1")
            y=request.form("b1")

            response.write("")
            response.write("")
            response.write("
")
            response.write("")       
            response.write(s)                
            response.write("
")
            response.write("
")
            response.write("
")
            response.write("
")
%>


File Name 5(a):        Res.html

                        Enter the name        :
            Enter the age            :
            Enter the gender      :
           

File Name 5(b):        Res.asp

<%
            dim na,age,gen

            na=request.form("na")
            age=request.form("age")
            gen=request.form("gen")

            response.write("")
            response.write ("YOUR NAME IS :"+na)
            response.write("")
            response.write ("YOUR AGE IS    :"+age)
            response.write("")
            response.write ("YOUR GENDER IS       :"+gen)
%>

File Name 6(a):        Id.html


get method   --> will display the passing data in address bar
post method --> will display the passing data in the document window


            Enter Username       :
            Enter Password        :
           
           

File Name 6(b):        Id.asp

<% @language="vbscript" %>
<%
            a1=request.form("u")
            a2=request.form("p")
            a3=request.form("b1")

            response.write("")
            response.write("User name :" & a1 & "
")
            response.write("Password   :" & a2)
            response.write("
")
%>

ADO (ActiveX Data Object)
1.            In ADO you can access or can do any changes in data in database table file.
2.            Data can be moved from server to client to do any changes and again return it to the server with the help of RDS (Remote Data Service), which is ADO.
3.            ADO and RDO are automatically installed with Microsoft IIS.

Steps to access database from an ASP page.
1.            Create ADO connection to a database.
2.            Open the database connection.
3.            Create ADO record set.
4.            Open the record set.
5.            Extract the data you need from the record set.
6.            Close the record set.
7.            Close the connection.
8.            Create the DSN (Data Source Name).

SQL Database and Table Creation Steps

1.            To create the database, give “CREATE DATABASE ”.
2.            To create the table, give “CREATE TABLE (col datatype,…)”.
3.            To insert the record, give “INSERT INTO VALUES(value1,…)”.
4.            To View the record, give “SELECT * FROM ”.

To execute SQL statements

1.            Type the command.
2.            Select the command with Shift + Arrow keys.
3.            Give F5 to execute the command.

ADO Connection statement

Syntax:
Set =Server.CreateObject(“Connection Name”)
To connect the database source.
Eg:      Set a=Server.CreateObject(“ADODB.Connection”)

Open the Connection

Syntax:
.Open “dsn=”,””,”
To open the connection using dsn name.
Eg:      a.Open “dsn=xyz”,”student”,”csc”

ADO Recordset Statement

Syntax:
Set =Server.CreateObject(“ADODB.Recordset”)
To attach the record set of the database.
Eg:      Set r=Server.CreateObject(“ADODB.Recordset”)

Open the Recordset

Syntax:
.Open “tb name”,
To open the recordset.
Eg:      r.Open “emp”,a

Close the Connection

Syntax:
.Close()
To close the connection.
Eg:      a.Close()

File Name 7(a):        Emp1.html

Enter code     :
Enter name   :
Enter salary   :
                       
                       

File Name 7(b):        Emp1.asp

<% @language ="vbscript" %>
<%
            a2=request.querystring("c")
            a3=request.querystring("n")
            a4=request.querystring("s")
            a5=request.querystring("b")

            set cn=Server.CreateObject("ADODB.connection")
            cn.open "dsn=jeb","student","csc"
            set rs=Server.CreateObject("ADODB.recordset")
            rs.open "emp",cn
            cn.execute "insert into emp values('"&a2&"','"&a3&"','"&a4&"')"
            cn.close()
            response.write("Record updated")
response.write("
Home Page")
%>

Table Creation with Structure in SQL

Create table emp(code int, name varchar(15),salary int)
Select * from emp
 

 
 













File Name 8(a):        Elist.html

Particular Employee Details to View


Enter code                          :
                       
                       

File Name 8(b):        Elist.asp

<%  @language="vbscript"%>
<%
a1=request.form("c")
            set cn=Server.CreateObject("ADODB.connection")
            cn.open "dsn=jeb","student","csc"

            set rs=Server.CreateObject("ADODB.recordset")
            rs.open "emp",cn

            cn.execute "select * from emp"

            response.write("Employee list
")

            while not rs.eof
                        if cint(a1)=rs.fields(0) then
                                    response.write(rs.fields(0) & rs.fields(1) & rs.fields(2) & "
")
            end if
                        rs.movenext
            wend
            cn.close()
response.write("
Home Page")
            %>

File Name 9(a):        Elist1.html

All Employee Details to View



File Name 9(b):        Elist1.asp

<%  @language="vbscript"%>
<%
            a1=request.form("c")
            set cn=Server.CreateObject("ADODB.connection")
            cn.open "dsn=jeb","student","csc"

            set rs=Server.CreateObject("ADODB.recordset")
            rs.open "emp",cn

            cn.execute "select * from emp"
            response.write("

Employee list


")

            while not rs.eof
                        response.write(rs.fields(0) & rs.fields(1) & rs.fields(2) & "
")
                        rs.movenext
wend
            cn.close()
response.write("
Home")
            response.write("
")
%>

FSO (File System Object)
Fill system object will create, modify and view the text files through asp file.

Objects of File

1.            Text file
2.            Folder
3.            Text Stream

FSO File Declaration

Syntax:
Set =Server.CreateObject(“Scripting.FileSystemObject”)
To create the FSO file and store it in a variable.
Eg:      Set f=Server.CreateObject(Scripting.FileSystemObject”)

Methods for FSO


Text File Creation Declaration

Syntax:
Set =Server.CreateTextFile(“path”,[overwrite])
[Overwrite] à It will return true or false. True for file exists. False for file not exists.
Eg:      Set ft=Server.CreateTextFile(“d:\test.txt”,true)

Text File Opening Declaration

Syntax:
Set =.OpenTextFile(“path”)
To open a text file and store it in a variable.
Eg:      Set x=ft.openTextFile(“d:\test.txt”)

Open Text File

Syntax:
.OpenTextFile(“Filename”,iomode,create,format)
To open the text file.
File name à String expression that identifies the filename to open.
io mode  à    It is optional which indicates input / output mode. There are 3 constants.
            1.         For Reading              à        1 (only for reading purpose not for writing)
            2.         For Writing                à        2 (only for writing purpose not for reading)
            3.         For appending          à        8 (only to add contents at the end of the file)
create à        It is a Boolean. True for new file creation, False for not created. Default is false.
format à        It is optional. If omitted the file is opened as ASCII mode.

Eg:      x.OpenTextFile(“d:\test.txt”1)

Close Text File

Syntax:
.Close()

Text Stream Object Methods

1.            Write Method
Syntax:
.Write(“String”)
To write a string in a text file.

2.            Writeline Method
Syntax:
.Writeline(“String”)
To write a sentence in a text file.

3.            Writeblanklines Method
Syntax:
.Writeblanklines(number)
To include blank lines in a text file.

4.            Read Method
Syntax:
.Read(Number of characters)
To read number of characters from a text file.

5.            Readline Method
Syntax:
.Readline()
To read a single line from the text file.

6.            Readall Method
Syntax:
.Readall()
To read all the contents from the text file.

7.            Skip Method
Syntax:
.Skip(Number of characters)
To skip the specified number of characters in an opened text file.

8.            Skipline Method
Syntax:
.Skipline()
To skip a single line in an opened text file.

FSO Progams


File Name 10:           Fso1.asp

To create a text file and read the contents.

<%
            dim i
            set fo=server.createobject("Scripting.FileSystemObject")
            set ft=fo.createtextfile("d:\text.txt",true)

            for i=0 to 5
                        ft.writeline("good morning")
            next
            ft.close()
            set txtfile=fo.opentextfile("d:\text.txt")

            for i=0 to 5
                        response.write txtfile.readline()
                        response.write("
            next
            txtfile.close()
%>

File Name 11:           Fso2.asp

To create file and write contents using

writeline and writeblankline methods.
<%
            set fso=server.createobject("Scripting.FileSystemObject")
            set file=fso.createtextfile("d:\text2.txt")
            file.writeline("Rohan")
            file.writeblanklines(1)
            file.writeline("lakshmi is studying in school")
            file.close()
            response.write("File is created")
            set tf=fso.opentextfile("d:\text2.txt")
            response.write "
"
            response.write ""
            response.write tf.skip(0)
            response.write tf.readall()
            tf.close()
%>

File Name 12:           Fso3.asp

To append the text in an existing text file

<%
            set fso=server.createobject("Scripting.FileSystemObject")
            set file=fso.opentextfile("d:\text2.txt",8)
            file.writeline("csc")
            file.writeline("computer")
            file.close()
            response.write("File is Append")
%>

File Name 13:           Fso4.asp

To display the contents of a file.

<%
            set fso=Server.CreateObject("Scripting.FileSystemObject")
            set file=fso.OpenTextFile("d:\text2.txt",1)
            for i = 1 to 8
                        response.write(file.readLine() & "
")
            next
            file.close()
%>

File Name 14:           Fso5.asp

To create a new file.

<%
            set fso=server.createobject("Scripting.FileSystemObject")
            set file=fso.createtextfile("d:\text3.txt",8,true)
            file.writeline("rose")
            file.writeline("jasmine")
            file.close()
            response.write("file is create")
%>

File Name 15:           Fso6.asp

To create, get, copy, move and delete a file.

<%
            dim i
            set fso=server.createobject("scripting.FileSystemObject")
            set file=fso.createtextfile("d:\text4.txt")
            file.writeline("Rose")
            file.writeline("lily")
            file.writeline("jasmine")
            file.writeline("sunflower")
            file.close()
            set afile=fso.getfile("d:\text4.txt")
            afile.copy("d:\sam.txt")
            afile.move("d:\sam1.txt")
            afile.delete
            response.write"File copied to sam move to sam1 and deleted sam1"
%>

File Name 16:           Fso7.asp

To display contents of the file by using endoffile option.

<%
            set fso=server.createobject("Scripting.FileSystemObject")
            set file=fso.opentextfile("d:\text2.txt")
            while not file.AtEndOfline
                        response.write(file.readline)& "
"
            wend
            file.close()
%>
        


* * *

Windows Shortcut Keys

More than 100 Keyboard Shortcuts must read & Share

Keyboard Shortcuts (Microsoft Windows)


1. CTRL+C (Copy)
2. CTRL+X (Cut)
3. CTRL+V (Paste)
4. CTRL+Z (Undo)
5. DELETE (Delete)
6. SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
7. CTRL while dragging an item (Copy the selected item)
8. CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
9. F2 key (Rename the selected item)
10. CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
11. CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
12. CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
13. CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
14. CTRL+SHIFT with any of the arrow keys (Highlight a block of text)
SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
15. CTRL+A (Select all)
16. F3 key (Search for a file or a folder)
17. ALT+ENTER (View the properties for the selected item)
18. ALT+F4 (Close the active item, or quit the active program)
19. ALT+ENTER (Display the properties of the selected object)
20. ALT+SPACEBAR (Open the shortcut menu for the active window)
21. CTRL+F4 (Close the active document in programs that enable you to have multiple documents open simultaneously)
22. ALT+TAB (Switch between the open items)
23. ALT+ESC (Cycle through items in the order that they had been opened)
24. F6 key (Cycle through the screen elements in a window or on the desktop)
25. F4 key (Display the Address bar list in My Computer or Windows Explorer)
26. SHIFT+F10 (Display the shortcut menu for the selected item)
27. ALT+SPACEBAR (Display the System menu for the active window)
28. CTRL+ESC (Display the Start menu)
29. ALT+Underlined letter in a menu name (Display the corresponding menu) Underlined letter in a command name on an open menu (Perform the corresponding command)
30. F10 key (Activate the menu bar in the active program)
31. RIGHT ARROW (Open the next menu to the right, or open a submenu)
32. LEFT ARROW (Open the next menu to the left, or close a submenu)
33. F5 key (Update the active window)
34. BACKSPACE (View the folder one level up in My Computer or Windows Explorer)
35. ESC (Cancel the current task)
36. SHIFT when you insert a CD-ROMinto the CD-ROM drive (Prevent the CD-ROM from automatically playing)

Dialog Box - Keyboard Shortcuts


1. CTRL+TAB (Move forward through the tabs)
2. CTRL+SHIFT+TAB (Move backward through the tabs)
3. TAB (Move forward through the options)
4. SHIFT+TAB (Move backward through the options)
5. ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
6. ENTER (Perform the command for the active option or button)
7. SPACEBAR (Select or clear the check box if the active option is a check box)
8. Arrow keys (Select a button if the active option is a group of option buttons)
9. F1 key (Display Help)
10. F4 key (Display the items in the active list)
11. BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)

Microsoft Natural Keyboard Shortcuts


1. Windows Logo (Display or hide the Start menu)
2. Windows Logo+BREAK (Display the System Properties dialog box)
3. Windows Logo+D (Display the desktop)
4. Windows Logo+M (Minimize all of the windows)
5. Windows Logo+SHIFT+M (Restore the minimize windows)
6. Windows Logo+E (Open My Computer)
7. Windows Logo+F (Search for a file or a folder)
8. CTRL+Windows Logo+F (Search for computers)
9. Windows Logo+F1 (Display Windows Help)
10. Windows Logo+ L (Lock the keyboard)
11. Windows Logo+R (Open the Run dialog box)
12. Windows Logo+U (Open Utility Manager)
13. Accessibility Keyboard Shortcuts
14. Right SHIFT for eight seconds (Switch FilterKeys either on or off)
15. Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
16. Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)
17. SHIFT five times (Switch the StickyKeys either on or off)
18. NUM LOCK for five seconds (Switch the ToggleKeys either on or off)
19. Windows Logo +U (Open Utility Manager)
20. Windows Explorer Keyboard Shortcuts
21. END (Display the bottom of the active window)
22. HOME (Display the top of the active window)
23. NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)
24. NUM LOCK+Plus sign (+) (Display the contents of the selected folder)

MMC Console keyboard shortcuts


1. SHIFT+F10 (Display the Action shortcut menu for the selected item)
2. F1 key (Open the Help topic, if any, for the selected item)
3. F5 key (Update the content of all console windows)
4. CTRL+F10 (Maximize the active console window)
5. CTRL+F5 (Restore the active console window)
6. ALT+ENTER (Display the Properties dialog box, if any, for theselected item)
7. F2 key (Rename the selected item)
8. CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)

Remote Desktop Connection Navigation


1. CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)
2. ALT+PAGE UP (Switch between programs from left to right)
3. ALT+PAGE DOWN (Switch between programs from right to left)
4. ALT+INSERT (Cycle through the programs in most recently used order)
5. ALT+HOME (Display the Start menu)
6. CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
7. ALT+DELETE (Display the Windows menu)
8. CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)
9. CTRL+ALT+Plus sign (+) (Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer.)

Microsoft Internet Explorer Keyboard Shortcuts


1. CTRL+B (Open the Organize Favorites dialog box)
2. CTRL+E (Open the Search bar)
3. CTRL+F (Start the Find utility)
4. CTRL+H (Open the History bar)
5. CTRL+I (Open the Favorites bar)
6. CTRL+L (Open the Open dialog box)
7. CTRL+N (Start another instance of the browser with the same Web address)
8. CTRL+O (Open the Open dialog box,the same as CTRL+L)
9. CTRL+P (Open the Print dialog box)
10. CTRL+R (Update the current Web page)
11. CTRL+W (Close the current window)

CakePHP Date Picker

Folder Structure: Controller:   File location - cakephp/src/controller/HomepageController.php namespace App\Controller; use...