24
ASP.NET Dr. Ralph Westfall May, 2011

ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links can’t provide

Embed Size (px)

Citation preview

Page 1: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

ASP.NET

Dr. Ralph WestfallMay, 2011

Page 2: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Web Development Problem

HTML designed to display static pages only interactive when user clicks links

can’t provide animation except How Do I Make An Animated GIF?

can’t create custom pages for specific types of customers

can’t use databases, spreadsheets, etc. no security capabilities in HTML itself

except hiding passwords <input type="password" etc.

using very long/random directory/file names works a bit, but it's not HTML

Page 3: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Solution 1: Client Side Scripts

JavaScript (dominant product) can do animation, rollovers, message boxes calculations, validation of user inputs incorporate customized content into pages

e.g. based on day/time, user inputs, etc. provide limited access to user’s system

system date, browser, plug-in informationset cookies (data for server for next visit)

Page 4: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Client Side Scripts (continued)

what (client side) JavaScript can’t do write meaningful data to files on the

server (other than cookies) provide adequate security for

access control (but JavaScript Source has some "hackish" scripts)

hiding proprietary code

Page 5: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Solution 2: Server Side Scripts

use common gateway interface (CGI)offer database & security capabilitieswritten in C, C++, Perl, Python, etc. relatively difficult to program & maintain

use server resources relatively inefficientlyseparate programs in addition to HTML but this is probably an advantage

Page 6: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Solution 3: "Classic" ASP

Microsoft's Active Server Pages released in 1996, works with Microsoft servers Windows Server 2008 free Visual Web Developer Express

2008 IDE includes a lightweight personal web server for developing ASP.NET applications

so does Visual Studio

Page 7: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Solution 3: ASP (continued)

simple languagecan go in same files as HTML codeprovides many of the capabilities of CGIuses server resources more efficiently than CGIusing ASP server extensions, can work with non-Microsoft servers, but …

Page 8: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

ASP.NET

major revision of ASP can use different languages, not just

VB.NET VB.NET code looks more like Java

than the VBScript used previously .NET code is compiled into MSIL

(Microsoft Intermediate Language) MSIL is then interpreted into machine

language that runs on the server

Page 9: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

ASP.NET: Many Languages

HTML (of course!)Visual Basic.NETcan also use C# and J# with VWDX.NET supports over 50 other languages C++ and JScript (Microsoft's version of

JavaScript) work with Visual Studio.NET other (non Microsoft) languages can

also work with Visual Studio.NET

Page 10: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Tools To Develop & Use ASP.NET

a tool to create code text editors: Notepad, TextPad, etc. HTML authoring tools: Dreamweaver,

FrontPage, etc. Visual Studio.NET, Visual Web

Developer Express 2008, Microsoft WebMatrix (2 free)

IIS or VWDX on your computer or free (for a while?) ASP.NET hosting

web browser

Page 11: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Simple ASP.NET

create ASP.NET projectProject>Add New Item>Web Formview Source window and add .NET code to file between <body> tags put:<% Response.Write("Hello, World!") %><p>The time is: <% = Now() %></p>

run code from that window

Page 12: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

ASP.NET Coding within HTML

use <% at start, %> at endon same line (inline)

<% = Time %>or on multiple lines (block) <%

Response.Write("<P>Hello, World!")

Response.Write 'cf. Console.Write %>

Page 13: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

ASP.NET Output in HTML

ASP inside a HTML tag <P>The time is: <% = Time %> use <% = followed by a variable or a

function that returns data, then %> variable can come from server itself, or

from client machine, or can be defined in code elsewhere in same or another ASP file

<% Dim strCar as String="Geo" %> <P>The car is: <% = strCar %>

Page 14: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Generating ASP Output - 2

ASP.NET code can write text and also data from ASP.NET variables <% Dim nAge as Integer = 22 nAge += 10 Response.Write("You will be" & nAge)

'text variable %>

Page 15: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Generating ASP Output - 3

can mix text, HTML, and ASP.NET variables in code this includes using ASP to write HTML

tags, in addition to writing variables and text

Page 16: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

fontsize.aspx

<%

Dim intI as Integer

For intI = 1 to 7

%> <!-HTML inside ASP loop->

<font size = "<% = intI %>" >

Size is <% = intI %> </font><br/>

<% Next %> <!--what will you see from this? Notes about " "-->

Page 17: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Using ASP.NET with Forms

use HTML or ASP page to create a form be sure all form fields have id = "[ ]"

and also name = "[ ]" 'same as for id=

use an ASP.NET page to process inputs action attribute in form has name of an

ASP.NET file, and use Input (Submit) button

form field values accessible to ASP as Request.QueryString("[form field name]")

Page 18: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

input.html

<form method="get"

action="output.aspx">

Last Name <input type="text"

name="custName" id="custName">

</form>

<!--need to refresh?-->

Page 19: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

output.aspx

<!-- Visual Studio generated headers--> <html><body> Input from form: <% Dim strCustName as String

strCustName = _ Request.QueryString("custName")

Response.Write("last name is " & _ strCustName)%>

</body></html>

Page 20: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Using ASP.NET with Forms - 2

if have more than just one text field, must have a Submit button on form

<input type="submit" [etc.]> after development would use

<form method="post" [etc.]> when using post, also need to change

every Request.QueryString to Request.Form in the ASP page identified by the action

Page 21: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Another Demonstration

Create: Web Site… ASP.NET Web Siteadd a Label to Default.aspx designer and expand it vertically and horizontally to occupy 25% of the screen (could make Height="[]px" and Width="[]px"double click the screen (outside of the label) to start a Page_Load Subpaste code on following page into Sub

Page 22: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

VB.NET Web Code

Dim i As IntegerDim colr() As String = {"000000", "333300",

_ "666600", "999900", "cccc00", "ffff00"}Dim output As String = ""For i = 0 To 5 output &= "<h1><font color=#" & colr(i)

_ & ">" & colr(i) & "</font></h1>"NextLabel1.Text = output

Page 23: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

Run Code

click Start(first time) modify the web.config…>OKview code and then make changes as necessary

Page 24: ASP.NET Dr. Ralph Westfall May, 2011. Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide

CIS 451 ASP.NET

ASP Code Samples