Académique Documents
Professionnel Documents
Culture Documents
CONTENTS INCLUDE:
Core ASP.NET
n
Installation
Get More Refcardz! Visit refcardz.com
n
ASP.NET Web Applications
n
The ASP.NET Webform Model
n
Web Controls
n
The Page Class
n
Hot Tips and more... By Holger Schwichtenberg
ASP.NET stands for “Active Server Pages .NET”, however An ASP.NET application consists of several .aspx files. An
the full name is rarely used. ASP.NET is a framework for the .aspx file can contain HTML markup and special ASP.NET
development of dynamic websites and web services. It is based markup (called Web Controls) as well as the code (Single Page
on the Microsoft .NET Framework and has been part of .NET Model). However, the Code Behind Model which comes with
since Version 1.0 was released in January 2002. The current a separate code file called, the “Code Behind File” (.aspx.
version named 3.5 Service Pack 1 was released in August 2008. cs or .aspx.vb), provides a cleaner architecture and better
The next version, 4.0, is expected to be released at the end of collaboration between Web designers and Web developers.
the year 2009. ASP.NET applications may contain several other elements
such as configuration files (maximum one per folder), a global
This Refcard summarizes the most commonly used core fun-
application file (only one per web application), web services,
ctions of ASP.NET. You will find this Refcard useful for some of
data files, media files and additional code files.
the most common tasks with ASP.NET, regardless of the version
you are using There are two types of Web projects: “Website Projects” (File/
New/Web Site) and “Web Application Projects” (File/New/
Installation Project/Web Application). “Website” is the newer model,
while Web Application Projects mainly exist for compatibility
The best development environment for ASP.NET is Microsoft’s with Visual Studio .NET 2002 and 2003. This Refcard will only
Visual Studio. You can either use the free Visual Web cover Web Site Projects. Most of this content is also valid for
Developer Express Edition (http://www.microsoft.com/express/ Web Applications.
vwd/) or any of the commercial editions of Visual Studio (e.g.
www.dzone.com
developed with ADS. On the production system you will use IIS n Latest tools & technologies
and only install the .NET Framework, because Visual Studio is n Hot tips & examples
CssClas The name of CSS class that is used for formatting the control
Figure 1: The Content of an ASP.NET Web Application Focus() Set the focus to this control
DataBind() Gets the data (if the control is bound to a data source)
The ASP.NET Webform Model
Init() Fires during initializtion of the page. Last chance to change
basic setting e.g. the culture of the current thread that
ASP.NET uses an object- and event-oriented model for web determines the behavior used for rendering the page.
pages. The ASP.NET Page Framework analyzes all incoming Load() Fires during the loading of the page. Last to change to do
any preparations.
requests as well as the .aspx page that the request is aimed
PreRender() Fires after all user defined event handlers have completed
at. The Page Framework creates an object model (alias control and right before rendering of the page starts. Your last
tree) based on this information and also fires a series of events. chance to make any changes to the controls on the page!
Event handlers in your code can access data, call external UnLoad() Event fires during the unloading of a page.
code in referenced .NET assemblies and manipulate the object Table 1: Core Members in the base class system. Web.UI.WebControls.WebControl.
model (e.g. fill a listbox or change the color of a textbox). After Tables 2, 3 and 4 list the most commonly used controls for ASP.
all event handlers have executed, the Page Framework renders NET web pages. However, there are more controls included
the current state of the object model into HTML tags with in the .NET platform and many more from third parties not
optional CSS formatting, JavaScript code and state information mentioned here.
(e.g. hidden fields or cookies). After interacting with the page, Control Purpose Important specific members in
the user can issue a new request by clicking a button or a link addition to the members inherited
from WebControl
that will restart the whole process.
<asp:Label> Static Text Text
Setting AppendDataBoundItems to true will add the For the CustomValidator you can optionally write
databound items to the static items declared in the a JavaScript function that performs client side vali-
Hot .aspx file. This will allow the user to select values that dation. The function has to look like this:
Tip don’t exist in the data source such as the values “All” Hot <script type=”text/javascript”>
function ClientValidate(source, args)
or “None” Tip {
if (x > 0) // Any condition
{ args.IsValid=true; }
else
Control Purpose Important specific members in { args.IsValid=false; }
addition to the members inherited }
from WebControl </script>
<asp:Drop Allows the user to select Items.Add(), Items.
DownList> a single item from a Remove(), DataSource,,
drop-down list DataTextField, DataValueField,
AppendDataBoundItems, The Page Class
SelectedIndez, SelectedItem,
SelectedValue, SelectedIndexChanged()
<asp:ListBox> Single or multiple Items.Add(), Items. All web pages in ASP.NET are .NET classes that inherit from
selection box Remove(), DataSource,,
DataTextField, DataValueField, the base class “System.Web.UI.Page”. The class Page has
AppendDataBoundItems, associations to several other objects such as Server, Request,
SelectedIndez, SelectedItem,
SelectedValue, SelectedIndexChanged(), Response, Application, Session and ViewState (see figure
Rows, SelectionMode
3). Therefore, developers have access to a wide array of
<asp:Check Multi selection check Items.Add(), Items.
BoxList> box group Remove(), DataSource,,
properties, methods and events within their code. Table 5 lists
DataTextField, DataValueField, the most important members of a Page and its dependent
AppendDataBoundItems,
SelectedIndez, SelectedItem, classes. Please note that the Page class has the class Control in
SelectedValue, SelectedIndexChanged(), its inheritance hierarchy and therefore shares a lot of members
RepeatLayout, RepeatDirection
with the WebControl class (e.g. Init(), Load(), Controls,
<asp:Radio Single selection radio Items.Add(), Items.
ButtonList> button group Remove(), DataSource,, FindControl). However, these members are not repeated here.
DataTextField, DataValueField,
AppendDataBoundItems,
SelectedIndez, SelectedItem,
SelectedValue, SelectedIndexChanged(),
RepeatLayout, RepeatDirection
<asp:Required Checks if a user changed the ControlToValidate, ErrorMessage, Page.IsPostBack True, if page is being loaded in response to a
FieldValidator> initial value of an input control Display, EnableClientScript, client postback. False if it is being loaded for
IsValid, InitialValue the first time.
<asp:Compare Compares the value entered by ControlToValidate, ErrorMessage, Page.IsAsync True, if the page is loaded in an
Validator> the user in an input control with Display, EnablesClientScript, asynchronous request (i.e. AJAX request)
the value entered in another IsValid, ValueToCompare, Type,
input control, or with a constant ControlToCompare
value Page.IsValid True, if all validation server controls in
the current validation group validated
<asp:Range Checks whether the value of ControlToValidate, ErrorMessage, successfully
Validator> an input control is within a Display, EnableClientScript,
specified range of values IsValid, MinimumValue, Page.Master Returns the MasterPage object associated
MaximumValue, Type with this page
<asp:Regular Checks if the user input ControlToValidate, ErrorMessage, Page.PreviousPage Gets the page that transferred control to
Expression matches a given regular Display, EnavleClientScript, the current page (only available if using
Validator> IsValid, ValidationExpression Server.Transfer, not available with Response.
Redirect)
<asp:Custom Performs custom checks on the ControlTValidate, ErrorMessage,
Validator> server and optional also on the Display, EnableClientScript, Page.SetFocus(Control ControlID) Sets the browser focus to the specified
client using JavaScript IsValid, ValidateEmptyText, control (using JavaScript)
Client ValidationFunction, Trace.Write Writes trace information to the trace log.
ServerValidate()
User.Identity.IsAuthenticated True, if the user has been authenticated.
Table 4: Validation controls for ASP.NET web pages
View State Single user on a single page Leaving the current page Hidden FIeld “ViewState” Object (any Page.ViewState Page.ViewState
serializable.NET
data type)
Session State Latest interaction of a single Limited number of minutes Cookie (“ASPSessionJD...”) Object. Object Page.Session Page.Session
user with the web page after the last request from or URL Parameter “(S(...))” must be serializable
the user plus server side store (local if the store is not
RAM, RAM on dedicated the local RAM
server or database)
Cookies A single User Closing of the browser or Cookie String Page.Response.Cookies Page.Response.Cookies
dedicated point in time
Application State All users Shutting down the web Local RAM Object Page.Application Page.Application
application
<!-- Display custom error pages for remote users --> production system and configure the target folder on the
<customErrors mode=”RemoteOnly” defaultRedirect=”GenericErrorPage. production system as an IIS web application (e.g. using the
htm”>
<error statusCode=”403” redirect=”NoAccess.htm” />
IIS Manager). The production web server will automatically
<error statusCode=”404” redirect=”FileNotFound.htm” /> compile the application during the first request and recompile
</customErrors>
automatically if any of the source files changed.
<!-- Turn on debugging -->
<compilation debug=”false”>
However, you can precompile the application into .NET
Figure 8: Typical setting in the web.config file.
assemblies to improve protection of your intellectual property
Please make sure you turn debugging off again and increase execution speed for the first user. Precompilation
Hot before deploying your application as this decreases can be performed through Visual Studio/Visual Web developer
Tip execution performance. (Menu “Build/Publish Website”) or the command line tool
aspnet_compiler.exe.
Bro
ugh
t to
you
by...
#8
ired
Insp e
by th
GoF ller con
tinu
ed
ndle
r doe
sn’t
have
to
d
Ch a in C ultip ecific o should cep
tab
is p
atte metho e
and n M
an ac ts th e if th
e up th
z.co
m sp cts
n
a e. is en sed
Download Now
Com reter b e je im d m se to
of ob runt le ple ks to e pas code
Use set ined at hand es im e chec ould b
RichFaces Spring Configuration
n
rp n n A ng g un til t
Inte Whe erm not
bei ua
lang e runtim it sh repeats e paren
tor det me or if
a rd
...
n
uest th
in so ethod ception proces e no
s mor
Itera tor ore req
n A ling
dm the e ar
tho nce
ptio th
Exce ion is sm to ha up th tered or
e ca
n
Ob
se Me NS ral
Refcardz.com
te fere in le pt ni ed coun avio
TER
exce mecha n pass
la
k re ted mp Beh
n
p is en
Tem s lis ct-
BIRT Windows Powershell
Exa .
PAT
a
quic
he
has ack. W tion uest to ject
es a s, a cep Ob
it
n
q
IG N id tt ern O bje call
st e ex
le th hand th
e re
S v
! V is
a ,
DE pro ign
p able grams ha nd to
UT ard eus cts
ABO
Patt
erns
refc
r (G
oF)
des of R
ents des cla
ss d
ia
exa
mp
le. obje
Inv
oke
r
JSF 2.0 Dependency Injection with EJB 3
arz
T 3 P a d o
al 2 ign ch p on, an uct enti M
ef
g in e s E a s tr le m O d
ori kD re. rma
ti on p C ma
n
boo Softwa to c their im om
BPM&BPMN Getting Started with Eclipse
re R
stru
cture
l Pa
s: U
ttern sponsib
ilitie
ship
s th
at c psu
Enca quest
re
late
and
e ha
to b llbacks
ca
.
nalit
y.
riant
times
or in
ling
the
invo
catio
DZone, Inc.
iora , and re
g
a v la tion Pur
pose the
que
uing
k fu
nctio led at va ject
hand ssin
roce to be
Beh nships ct re ISBN-13: 978-1-934238-49-3
ob p
be as ac nd
e ha eded. the
1251 NW Maynard
llb us y
o b je c a n ed ca to b from rono tionalit y need
ith o
ne ch
that
ti ne ed s is d
You le asyn func an
rela ls w ips sts ne quest
Reque y of re
n
be de
coup
ate
the rn the without n it is ar
Dea e. nsh cilit d patte ssing entatio particul
Sco
pe:
ntim s re
latio pe
Use
n A hist
or
voke
r sh
ould
n
to fa
used e comm
an ce
pro implem ents its ting. ISBN-10: 1-934238-49-X
Cary, NC 27513
Whe for
toty
n
ec
clas The in ely al m
ject ed at ru Pro wid th
are utilizing a job q of the
ueue actu d imple
ue is
exp
Ob with
n
C ues ue
g que the que
n ls
50795
y to e
h a ea e. xy q ue s. B en d g en
be c e: D ile tim Pro Job orithm be giv knowle that is terface
cop r S g n ct in
p rato er mp
le of al ed ca to have d obje of the
ss S at com Deco serv Exa ut an nes
888.678.0399
.com
tory
C
Abst
Ada
pte
r C
Fac
Flyw
eigh
t B
State
Stra
teg
y
od
919.678.0300
z
S S
ter B Meth
w. d
er
B
Inte
rpre
tor
B
Tem
plate
Build B
Itera Visit
C r B
$7.95
f diato
makers. DZone offers something for everyone, including news, B
in o
Cha nsibili
Resp
o
d
ty
B
Me
Me
men
to
Ob
ject
Beh
avio
ral
refcardz@dzone.com
man B
C om
Version 1.0
req
a ndle
Copyright © 2009 DZone, Inc. All rights reserved.
nt No part of this publication dle
r 2 may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical,
+ h
Clie Han
ete
photocopying, or otherwise, without prior written permission of Cthe
oncr publisher.
req
uest
() Reference: Programming Microsoft ASP.NET 3.5, Dino Esposito, Microsoft Press, 2008
s
ndle
+ha
tern
r 1 king m
y lin .c o
ndle st b
teH
a
req
ue z one
cre () le a w.d
Con req
uest
y to
hand | ww