Download CIS 451: E-Commerce Introduction to ASP

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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 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
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
information
 set cookies (data for server for next visit)
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
Solution 2: Server Side Scripts
use common gateway interface (CGI)
offer database & security capabilities
written in C, C++, Perl, Python, etc.

relatively difficult to program & maintain
use server resources relatively
inefficiently
separate programs in addition to HTML

but this is probably an advantage
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
Solution 3: ASP (continued)
simple language
can go in same files as HTML code
provides many of the capabilities of CGI
uses server resources more efficiently
than CGI
using ASP server extensions, can work
with non-Microsoft servers, but …
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
ASP.NET: Many Languages
HTML (of course!)
Visual Basic.NET
can 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
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
Simple ASP.NET
create ASP.NET project
Project>Add New Item>Web Form
view 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
ASP.NET Coding within HTML
use <% at start, %> at end
on same line (inline)
<% = Time %>
or on multiple lines (block)
<%
Response.Write("<P>Hello, World!")
Response.Write 'cf. Console.Write
%>
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 %>
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
%>
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
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 " "-->
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]")
input.html
<form method="get"
action="output.aspx">
Last Name <input type="text"
name="custName" id="custName">
</form>
<!--need to refresh?-->
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>
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
Another Demonstration
Create: Web Site… ASP.NET Web Site
add 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 Sub
paste code on following page into Sub
VB.NET Web Code
Dim i As Integer
Dim 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>"
Next
Label1.Text = output
Run Code
click Start
(first time) modify the web.config…>OK
view code and then make changes as
necessary
CIS 451 ASP.NET
ASP Code Samples