700 likes | 900 Views
Web Design & Programming. <% ASP %> Mr. Baha & Dr.Husam Osta 2014. Outlines. What is ASP? Internet Information Services How Does ASP Differ from HTML? What can ASP do for you ? ASP Advantages & Technology ASP Basic Syntax Rules ASP Variables ASP Time based / Date & Time Forms
E N D
Web Design & Programming <% ASP %> Mr. Baha & Dr.HusamOsta 2014
Outlines • What is ASP? • Internet Information Services • How Does ASP Differ from HTML? • What can ASP do for you? • ASP Advantages & Technology • ASP Basic Syntax Rules • ASP Variables • ASP Time based / Date & Time • Forms • Loops • Array • Radio / Check box • Sending emails using ASP • Application Object Methods • Examples <<<< • Functions • Passing Variables in a URL • Passing variables with forms • Sessions
What is ASP? • ASP stands for Active Server Pages ,or classical ASP • ASP is Microsoft's first server side scripting engine • It enables you to make dynamic and interactive web pages. • ASP is a program that runs inside Internet Information Services (IIS) • An ASP file can contain • Text, HTML, XML, and scripts • Scripts in an ASP file are executed on the server • The default scripting language used for ASP is VBScript, or others like JScript • An ASP file has the file extension “.asp”
Internet Information Services (IIS) • Internet Information Services is an extensible web server created by Microsoft for use with Windows family. • IIS supports: • HTTP, HTTPS, FTP, FTPS, SMTP and NNTP. • It is an integral part of Windows family since Windows NT 4.0, though it may be absent from some edition (e.g. Windows XP Home edition). • IIS is not turned on by default when Windows is installed.
How Does ASP Differ from HTML? • When a browser requests an HTMLfile • the server returns the file
How Does ASP Differ from HTML? • When a browser requests an ASPfile • IIS passes the request to the ASP engine. • The ASP engine reads the ASP file, line by line, and executes the scripts in the file. • Finally, the ASP file is returned to the browser as plain HTML
What can ASP do for you? • Dynamically edit, change, or add any content of a Web page • Respond to user queries or data submitted from HTML forms • Access any data or databases and return the results to a browser • Customize a Web page to make it more useful for individual users
Advantages of ASP … • The advantages over other technologies, are • Simplicity • speed • Provide security since the code cannot be viewed from the browser • Clever ASP programming can minimize the network traffic
ASP.Net Technology • It is a unified Web development model • It includes services necessary to build enterprise-class web applications with minimum of coding. • This technology is developed under the .Net framework that is provided in the visual studio platform
ASP Basic Syntax Rules • An ASP file normally contains HTML tags, just like an HTML file. • An ASP file can also contain server scripts, surrounded by the delimiters <% and %>. • The command response.write is used to write output to a browser. • Example <html> <body> <% response.write(“My first ASP script!”) %> </body> </html>
ASP Basic Syntax Rules • ASP can format text with HTML tags <html><body> <% response.write("<h2>You can use HTML tags to format the text!</h2>") %> <%response.write("<p style='color:#0000ff'>This text is styled with the style attribute!</p>")%> </body></html>
Your first ASP page HLTML ASP
ASP Variables • Variables are used to store information. • The example demonstrates • how to declare a variable, assign a value to it, and use the value in a text. <!DOCTYPE html><html><body> <% dim name name="Donald Duck"response.write("My name is: " & name) %></body></html>
Time-based Time-based greeting using VBScriptThis it will display a different message to the user depending on the time on the server.
<html><body> <% dim h h=hour(now()) response.write("<p>" & now())response.write("</p>") If h<12 thenresponse.write("Good Morning!") elseresponse.write("Good day!") end if %></body></html>
Formatting time and dates • FormatDateTime(Date[, NamedFormat]) • The NamedFormat argument may take the following values: • vbLongDate • vbShortDate • vbLongTime • vbShortTime
ASP – Date & Time • <!DOCTYPE html><html><body> <%response.write(FormatDateTime(date(),vbgeneraldate))response.write("<br>")response.write(FormatDateTime(date(),vblongdate))response.write("<br>")response.write(FormatDateTime(date(),vbshortdate))response.write("<br>")response.write(FormatDateTime(now(),vblongtime))response.write("<br>")response.write(FormatDateTime(now(),vbshorttime)) %><p> Syntax for FormatDateTime: FormatDateTime(date,namedformat).</p></body></html>
Functions for time and dates • YearReturns the current year from a date - with today's date, it returns: 2014 • MonthReturnsthe current month from a date - with today's date, it returns: 1 • DayReturnsthe current day of the month from a date - with today's date, it returns:29 • HourReturnsthe current hour from a time - with the current time, it returns: 8 • MinuteReturnsthe current minute from a time - with the current time, it returns: 10 • SecondReturnsthe current second from a time - with the current time, it returns: 28
Weekday function • Weekday Returns the current day of the week from a date • NOTE: this function has to be called with the argument "the first day of the week" (eg. Monday or Sunday) as well- like this: Weekday(Now,vbMonday)
ASP Forms • Get • A form with method="get“ is how to interact with the user, with >>>> Request.QueryStringcommand. • Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send. • Post • A form with method="post“ is how to interact with the user, with >>>> Request.Form command. • Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. • Radiobuttons • A form with radio buttons is how to interact with the user, through radio buttons, with >>>> Request.Form command.
ASP Forms – Get / Post method <html><body> <form action="demo_reqquery.asp" method="get">Your name: <input type="text" name="fname" size="20" /><input type="submit" value="Submit" /></form> <%dim fnamefname=Request.QueryString("fname") (Or use this (request.form))If fname<>"" ThenResponse.Write("Hello " & fname & "!<br>")Response.Write("How are you today?")End If%></body></html>
Loops “For loop” For Initializion To Expressions Statement Next
For Initializion To Expressions Statement Next Loops “For loop example”
Do Statement Loop {While | Until} condition Do ... Loop • Do {While | Until} condition Statement Loop OR Do Statement Loop {While | Until} condition
Example of Loop <!DOCTYPE html><html><body><%dim i for i=1 to 6response.write("<h" & i & ">Heading " & i & "</h" & i & ">")next%></body></html>
Conditions : If ..Then..Else If conditionThen statement Else statement End If
Logical Operators = Equals< Less than> Greater than<= Less than or equal to> = Greater than or equal to<> Not equal to AND OR NOT
Select ... Case Select Case Expression Case 1 statement Case 2 statement Case Else statement End Select
Declare an Array • Arrays are used to store a series of related data items. • The example demonstrates how to declare an array that stores names. <!DOCTYPE html><html><body> <% Dim famname(5),ifamname(0) = "Jan Egil"famname(1) = "Tove"famname(2) = "Hege"famname(3) = "Stale"famname(4) = "Kai Jim"famname(5) = "Borge" For i = 0 to 5response.write(famname(i) & "<br>") Next %></body></html>
Arrays • An array is a set of indexed elements where each has its own, unique identification number. • Ex: <% Dim fruitlist, arrFruits fruitlist= "apples, pears, bananas, oranges, lemons" arrFruits= Split(fruitlist,",") %>
Array Ex: <% Dim fruitlist, arrFruits fruitlist= "apples, pears, bananas, oranges, lemons" arrFruits= Split(fruitlist,",") Response.Write"<p>The list of fruits:</p> Response.Write"<ul>“ Response.Write"<li>" & arrFruits(0) & "</li>“ Response.Write"<li>" & arrFruits(1) & "</li>" Response.Write"<li>" & arrFruits(2) & "</li>“ Response.Write"<li>" & arrFruits(3) & "</li>“ Response.Write"<li>" & arrFruits(4) & "</li>“ Response.Write"</ul>" %>
Arrays • http://html.net/tutorials/asp/lesson8.asp
Radiobuttons <html><% dim carscars=Request.Form("cars")%> <body><form action="demo_radiob.asp" method="post"><p>Please select your favorite car:</p><input type="radio" name="cars"<%if cars="Volvo" then Response.Write("checked")%> value="Volvo">Volvo</input><br><input type="radio" name="cars"<%if cars=“Benz" then Response.Write("checked")%> value=“Benz">Benz</input><br><input type="radio" name="cars"<%if cars="BMW" then Response.Write("checked")%> value="BMW">BMW</input><br><br> <input type="submit" value="Submit" /></form> <% if cars<>"" thenResponse.Write("<p>Your favorite car is: " & cars & "</p>")end if%></body></html>
Check box <html><body><% fruits=Request.Form("fruits")%><form action="demo_checkboxes.asp" method="post"><p>Which of these fruits do you prefer:</p><input type="checkbox" name="fruits" value="Apples“ <% if instr(fruits,"Apple") then Response.Write("checked")%> Apple> <br><input type="checkbox" name="fruits" value="Oranges“ <%if instr(fruits,"Oranges") then Response.Write("checked")%> Orange> <br><input type="checkbox" name="fruits" value="Bananas“ <%if instr(fruits,"Banana") then Response.Write("checked")%> Banana> <br><input type="submit" value="Submit"></form> <% if fruits<>"" then %><p>You like: <%Response.Write(fruits)%></p><% end if %> </body></html>
ASP Sending e-mail with CDOSYS • CDOSYS is a built-in component in ASP. This component is used to send e-mails with ASP. • CDO (Collaboration Data Objects) is a Microsoft technology that is designed to simplify the creation of messaging applications. • CDOSYS is a built-in component in ASP.
Application objects methods <html> <body> <% response.write("The default LCID for this page is: " &Session.LCID& "<br>") response.Write(" Session ID is " &Session.SessionID) response.write("</p>") response.write("Default Timeout is: " &Session.Timeout& " minutes.") %> </body> </html>
In Vbscript – find average <html> <body> <script type="text/vbscript"> dim number1 dim number2 dim answer number1 = cInt (InputBox("Type the first number") ) number2 = cInt (InputBox("Type the second number")) answer = (number1 + number2)/2 msgBox" Average of " number1 & number2 & " = " & answer </script> </body> </html>
In Vbscript – find smaller # <html> <body> <script type="text/vbscript"> dim num1 dim num2 num1 = cInt (InputBox("Type the first number") ) num2 = cInt (InputBox("Type the second number")) If num1 < num2 then msgBox" Minimum is " & num1 If num2 < num1 then msgBox" Minimum is " & num2 </script> </body> </html>
ASP text box types ! • The TextMode property accepts the following three values: • SingleLine— displays a single-line input field. • MultiLine— displays a multi-line input field. • Password— displays a single-line input field in which the text is hidden. • A basic TextBox:<asp:TextBox id="tb1" runat="server" />A password TextBox:<asp:TextBox id="tb2" TextMode="password" runat="server" />A TextBox with text:<asp:TextBox id="tb4" Text="Hello World!" runat="server" />A multiline TextBox:<asp:TextBox id="tb3" TextMode="multiline" runat="server" />
Find the output example ! <form runat="server"> <asp:DropDownList id="drop1" runat="server"> <asp:ListItem>fall</asp:ListItem> <asp:ListItem>spring</asp:ListItem> <asp:ListItem>summer</asp:ListItem> </asp:DropDownList> <asp:Button Text="Submit" OnClick="submit" runat="server"/> <p><asp:label id="mess" runat="server"/></p> </form>
Find the output example ! <form runat="server"> Enter your name: <asp:TextBox id="txt1" runat="server" /> <asp:password id="pass1" runat="server" /> <p><asp:Label id="lbl1" runat="server" /></p> <asp:Calendarrunat="server" /> <asp:ButtonOnClick="submit" Text="Submit" runat="server" /> </form>