170 likes | 303 Views
Introduction to ASP.NET. Please use speaker notes for additional information!. ASP.NET. Most of this code is standard HTML. <html> <head><title>First ASP.NET</title></head> <body> <center> <h2>Hello CIS47 students!</h2> <p><%Response.Write(now())%></p> </center> </body> </html>.
E N D
Introduction to ASP.NET Please use speaker notes for additional information!
ASP.NET Most of this code is standard HTML. <html> <head><title>First ASP.NET</title></head> <body> <center> <h2>Hello CIS47 students!</h2> <p><%Response.Write(now())%></p> </center> </body> </html> The code inside the <%…%> tags is executed on the server. These are called code render blocks. The function now() returns the current date and time. When you want to write to the HTML output stream, you use the command Response.Write. This is a very basic ASP.NET file. Note that it saved with a .aspx extension and is embedded in HTML code. I saved this as test1.aspx.
ASP.NET <html> <head><title>First ASP.NET</title></head? <body> <center> <h2>Hello CIS47 students!</h2> <p><%Response.Write(now())%></p> </center> </body> </html>
ASP.NET <html> <head><title>HTML & CSS</title></head> <body> <% response.write("<h1>Formatted text!</h1>") %> <% response.write("<h2>Note that you can use HTML tags in asp.net</h2>") %> <% response.write("<p style='color:red'>You can also use CSS style attributes!</p>") %> </body> </html>
ASP.NET The variable rslt has been defined with a dim statement. <html> <head><title>Variables</title></head> <body> <% dim rslt rslt = 5 * 6 response.write("5 times 6 = " & rslt) %> </body> </html> A calculation is done and the answer is stored in rslt. The rslt is written out concatenated with a literal.
ASP.NET <html> <head><title>Variables</title></head> <body> <% dim first dim last first = "John" last = "Doe" response.write("The name is " & first & " " & last) %> </body> </html> The first and last name were both given a variable name, a literal was assigned to that variable name and then in the response.write, the variable names were concatenated together. This is the code you see when you view the source.
ASP.NET <html> <head> <title>Playing with time tests!</title> </head> <body bgcolor=beige> The CIS Department at BCC runs both day and evening classes. <ul> <li>Day classes run from 8:00AM until 4:00PM</li> <li>Night classes run from 4:00PM until 10:00PM</li> </ul> <BR> <% dim tdate dim thr tdate=now() thr = hour(now()) response.write("After checking our clock for the date " & tdate) if thr >=22 response.write(" the campus is closed") else if thr >=16 then response.write(" night school schedule is in effect!") else response.write(" day school schedule is in effect!") end if end if %> </body> </html> Declaring variables and assigned the current date/time to tdate and the hour of that date to thr. I then wrote the date and after checking the hour with an if wrote the appropriate message.
ASP.NET Created from HTML code. Created from ASP.NET code.
<html> <head> <title>Playing with time tests!</title> </head> <body bgcolor=beige> The CIS Department at BCC runs both day and evening classes. <ul> <li>Day classes run from 8:00AM until 4:00PM</li> <li>Night classes run from 4:00PM until 10:00PM</li> </ul> <BR> <% dim tdate dim thr tdate=now() thr = hour(now()) response.write("After checking our clock for the date " & tdate) if thr >=22 response.write(" the campus is closed") else if thr >=16 then response.write(" night school schedule is in effect!") else response.write(" day school schedule is in effect!") end if end if %> </body> </html> View source code.
ASP.NET <html> <head> <title>Math facts</title> </head> <body bgcolor=beige> <h1>Math Facts</h1> <% dim i as integer dim j as integer dim ans as integer for i = 1 to 3 for j = 1 to 3 ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") next next %> </body> </html> The for loop establishes a starting point (in this case 1), an ending point (in this case 3) and by default an increment of 1 each time the loop is executed.
<html> <head><title>Math While Loop</title></head> <body> <body bgcolor=black text=red> <h1>Math Facts</h1> <% dim i as integer dim j as integer dim ans as integer i = 1 Do While i < 4 j = 1 Do While j < 4 ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop i = i + 1 loop %> </body> </html> ASP.NET Initialize prior to entering the loop. Condition to terminate the loop is with the while. Increment the last thing in the loop for this code.
ASP.NET <html> <head><title>Math While Loop</title></head> <body> <body bgcolor=green text=beige> <h1>Math Facts</h1> <% dim i as integer dim j as integer dim ans as integer i = 1 Do Until i > 3 j = 1 Do Until j > 3 ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop i = i + 1 loop %> </body> </html> Note that now the test until i > 3 or j > 3. Compare that to the while that used while < 4.
ASP.NET <html> <head><title>Math While Loop</title></head> <body> <body bgcolor=green text=beige> <h1>Math Facts</h1> <% dim i as integer dim j as integer dim ans as integer i = 1 Do j = 1 Do ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop Until j > 3 i = i + 1 loop Until i > 3 %> </body> </html> Note that the until can be coded with the loop statement rather than the Do statement.
ASP.NET <html> <head><title>Math While Loop</title></head> <body> <body bgcolor=green text=beige> <h1>Math Facts</h1> <% dim i as integer dim j as integer dim ans as integer i = 4 Do j = 4 Do ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop until j > 3 i = i + 1 loop until i > 3 %> </body> </html> In this code, i and j were initialized at 4.
ASP.NET <html> <head><title>Math While Loop</title></head> <body> <body bgcolor=black text=red> <h1>Math Facts</h1> <% dim i as integer dim j as integer dim ans as integer i = 4 Do While i < 4 j = 4 Do While j < 4 ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop i = i + 1 loop %> </body> </html> This code initializes i and j at 4.
ASP.NET <html> <head><title>Array</title></head> <body> <body bgcolor=maroon text=beige> <h1>Departments</h1> <% Dim deptarray(4),indx deptarray(0) = "Womens" deptarray(1) = "Mens" deptarray(2) = "Girls" deptarray(3) = "Boys" deptarray(4) = "Infants" For indx = 0 to 4 response.write("The department for " & indx & " is " & deptarray(indx) & "<br />") Next %> </body> </html> Establishes the array of 4 which includes elements from 0 through 4 and establishes that the index to access the elements of the array is named indx. Establishes the content of the array. The 0th element is Womens, the 1st element is Mens, the 2nd element is girls etc. Writes the index (named indx) and the element in the array that indx points to.