Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Introduction to ASP.NET Please use speaker notes for additional information!"— Presentation transcript:

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

2 First ASP.NET Hello CIS47 students! 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.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.

3 ASP.NET First ASP.NET </head? Hello CIS47 students!

4 ASP.NET HTML & CSS <% response.write(" Formatted text! ") %> <% response.write(" Note that you can use HTML tags in asp.net ") %> <% response.write(" You can also use CSS style attributes! ") %>

5 Variables <% dim rslt rslt = 5 * 6 response.write("5 times 6 = " & rslt) %> ASP.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.

6 ASP.NET Variables <% dim first dim last first = "John" last = "Doe" response.write("The name is " & first & " " & last) %> 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.

7 Playing with time tests! The CIS Department at BCC runs both day and evening classes. Day classes run from 8:00AM until 4:00PM Night classes run from 4:00PM until 10:00PM <% 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 %> ASP.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.

8 ASP.NET Created from HTML code. Created from ASP.NET code.

9 Playing with time tests! The CIS Department at BCC runs both day and evening classes. Day classes run from 8:00AM until 4:00PM Night classes run from 4:00PM until 10:00PM <% 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 %> View source code.

10 Math facts Math Facts <% 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 & " ") next %> ASP.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.

11 Math While Loop Math Facts <% 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 & " ") j = j + 1 loop i = i + 1 loop %> ASP.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.

12 Math While Loop Math Facts <% 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 & " ") j = j + 1 loop i = i + 1 loop %> Note that now the test until i > 3 or j > 3. Compare that to the while that used while < 4. ASP.NET

13 Math While Loop Math Facts <% 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 & " ") j = j + 1 loop Until j > 3 i = i + 1 loop Until i > 3 %> Note that the until can be coded with the loop statement rather than the Do statement. ASP.NET

14 Math While Loop Math Facts <% 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 & " ") j = j + 1 loop until j > 3 i = i + 1 loop until i > 3 %> ASP.NET In this code, i and j were initialized at 4.

15 Math While Loop Math Facts <% 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 & " ") j = j + 1 loop i = i + 1 loop %> This code initializes i and j at 4. ASP.NET

16 Array Departments <% 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) & " ") Next %> ASP.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.


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

Similar presentations


Ads by Google