+ All Categories
Home > Documents > Introduction to ASP.NET Please use speaker notes for additional information!

Introduction to ASP.NET Please use speaker notes for additional information!

Date post: 13-Dec-2015
Category:
Upload: kenneth-lang
View: 227 times
Download: 4 times
Share this document with a friend
Popular Tags:
16
Introduction to ASP.NET Please use speaker notes for additional information!
Transcript
Page 1: Introduction to ASP.NET Please use speaker notes for additional information!

Introduction to ASP.NET

Please use speaker notes for additional information!

Page 2: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>First ASP.NET</title></head><body><center><h2>Hello CIS47 students!</h2><p><%Response.Write(now())%></p></center></body></html>

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.

The code inside the <%…%> tags is executed on the server. These are called code render blocks.

ASP.NETASP.NET

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.

Most of this code is standard HTML.

Page 3: Introduction to ASP.NET Please use speaker notes for additional information!

ASP.NETASP.NET

<html><head><title>First ASP.NET</title></head?<body><center><h2>Hello CIS47 students!</h2><p><%Response.Write(now())%></p></center></body></html>

Page 4: Introduction to ASP.NET Please use speaker notes for additional information!

ASP.NETASP.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>

Page 5: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>Variables</title></head><body><% dim rsltrslt = 5 * 6response.write("5 times 6 = " & rslt)%></body></html>

ASP.NETASP.NET

The variable rslt has been defined with a dim statement.

A calculation is done and the answer is stored in rslt.

The rslt is written out concatenated with a literal.

Page 6: Introduction to ASP.NET Please use speaker notes for additional information!

ASP.NETASP.NET

<html><head><title>Variables</title></head><body><% dim firstdim lastfirst = "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.

Page 7: Introduction to ASP.NET Please use speaker notes for additional information!

<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 tdatedim thrtdate=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>

ASP.NETASP.NET

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.

Page 8: Introduction to ASP.NET Please use speaker notes for additional information!

ASP.NETASP.NET

Created from HTML code.

Created from ASP.NET code.

Page 9: Introduction to ASP.NET Please use speaker notes for additional information!

<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 tdatedim thrtdate=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.

Page 10: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>Math facts</title></head><body bgcolor=beige><h1>Math Facts</h1><%dim i as integerdim j as integerdim ans as integerfor i = 1 to 3 for j = 1 to 3 ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") nextnext %></body></html>

ASP.NETASP.NET

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.

Page 11: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>Math While Loop</title></head><body><body bgcolor=black text=red><h1>Math Facts</h1><% dim i as integerdim j as integerdim ans as integeri = 1Do While i < 4 j = 1 Do While j < 4 ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop i = i + 1loop %></body></html>

ASP.NETASP.NET

Initialize prior to entering the loop.

Increment the last thing in the loop for this code.

Condition to terminate the loop is with the while.

Page 12: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>Math While Loop</title></head><body><body bgcolor=green text=beige><h1>Math Facts</h1><% dim i as integerdim j as integerdim ans as integeri = 1Do Until i > 3 j = 1 Do Until j > 3 ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop i = i + 1loop %></body></html>

Note that now the test until i > 3 or j > 3. Compare that to the while that used while < 4.

ASP.NETASP.NET

Page 13: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>Math While Loop</title></head><body><body bgcolor=green text=beige><h1>Math Facts</h1><% dim i as integerdim j as integerdim ans as integeri = 1Do j = 1 Do ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop Until j > 3 i = i + 1loop Until i > 3 %></body></html>

Note that the until can be coded with the loop statement rather than the Do statement.

ASP.NETASP.NET

Page 14: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>Math While Loop</title></head><body><body bgcolor=green text=beige><h1>Math Facts</h1><% dim i as integerdim j as integerdim ans as integeri = 4Do j = 4 Do ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop until j > 3 i = i + 1loop until i > 3 %></body></html>

ASP.NETASP.NET

In this code, i and j were initialized at 4.

Page 15: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>Math While Loop</title></head><body><body bgcolor=black text=red><h1>Math Facts</h1><% dim i as integerdim j as integerdim ans as integeri = 4Do While i < 4 j = 4 Do While j < 4 ans = i + j response.write(i & " + " & j & " = " & ans & "<br />") j = j + 1 loop i = i + 1loop %></body></html>

This code initializes i and j at 4.

ASP.NETASP.NET

Page 16: Introduction to ASP.NET Please use speaker notes for additional information!

<html><head><title>Array</title></head><body><body bgcolor=maroon text=beige><h1>Departments</h1><% Dim deptarray(4),indxdeptarray(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>

ASP.NETASP.NET

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.


Recommended