You are on page 1of 293



 
  
  
 


 
   
 

 

: 
 
 
  

:   
.              !
   

:!"
 $  
 
    
 
    #  $ %      &
.%    
   ' (  #  *
) +   ,  
-  !. 
56 6 # *7          .#     &  .# /0  12 3 4 (4 * !+
.& 

:  # $%&
:(,8 *# 0. !  9 
 
 
   9  -
 
 
    
 
    9;& -
< = 7+>  5  5  # -
 
 
   !  5?, 5  -
1@ &    5,
 A=4 IIS  84  # + -

' " % 
  (   2)  5$# (8 B 2 5  .  5, * C    .
<8    *  .5$# /0. *@  , HTML 5$# * 4 
.HTTP !  *+  (,8

Universal Knowledge Solutions s.a.l 1


" ()  )
 !

:$ #

&    !  5$# 5 5  B$4  
 
   F
5$#    (,8 !
   * ?= 8 C *8#  ,HTML. +  


 *+= !  ,8# 5 & 1@   G <%8  
 
   F
.5 , H  I2 2 5  8@ 1 *

 0 #  J   + B 2 5  


  ( 
) %    /0.   
 
      ( (   )  5$# '# 8 (,8 
 
.  

(1) ' 
* () & " ()

 ‫م‬
‫ص‬# ‫  ا‬$%  ‫ا‬   ‫ا ب‬
&  ' ‫ا‬ (‫)ا ﺏن‬  ‫ا‬ 1
‫!( ا ﺏن‬
!

 ‫م‬
 ‫ا‬   ‫ا ب‬
‫ص‬# ‫  ا‬$%
(‫)ا ﺏن‬  ‫ا‬ 2
&  ' ‫ا‬
‫!( ا م‬ !

 $%  ‫م‬
 ‫ا‬   ‫ا ب‬
‫ت‬$+‫ﺹ‬
Html  - (‫)ا ﺏن‬  ‫ا‬ 3
./0 ‫وی‬$+ ‫ا‬
‫ص‬

Universal Knowledge Solutions s.a.l 2


 @;   * 7   
 2  
 
   % + ' 
.($ ! '#)    1 

:  *$      *8# 


  $#   9  += 8 HTTP ,  (4 (   ) '# * o
(URL) !    $ 
   (4 += 8 /   , 9, 8 K$  ,  , o

C  $ I0  , $ =  ' *+= !  /


 + $  > *7

    /
 + $  > *7 $ !        ! $#
.  (4 , B$ * 4  

(2) ' 
* () & " ()

:   5&$ B$4 2 2       *8#   8 


M  
 
   (,8 $# I$ L1 $

.M 
 
   (,8 $# I$ L2 $

.( HTML 5 8 (,8 I$) 


    2 (,8 $# I$ & L3 $

: -.
  
 
   (,8  
 
   (,8 $# I$ 2 +
.<  7 (> $      *8# .8 I

:   5&$ B$4 2 2       *8#   8 


Universal Knowledge Solutions s.a.l 3


 0 # 
 I
 :
* ()  )
! 0  1  / 1 
 /0. (,8 ,F $#, C;   *@  , $# ! %$ 
 
.  
 
  

 0 # 
 I
 :" ()  )
! 0  1  / 2 
,F $# * 4 *@  *@   , !  * 2 ! $# ! %$ 
 
.  
 
    /0. (,8

* :( 2 HTML  
 0 1  ) )
! & 0  1   /3 
.   I0  (4 $# 

: -.
  
 
   (,8  
 
   (,8 $# I$ 2 +
.<  7 (> $      *8# .8 I

(1) '" ()  )
 ! %& 

 
 
        ! *  ,8 !? *J 0. (,8 
N
.  *
) +  ,  
-  .2   *;   
 
  

:
* ()  )
 !

: 
- 
DHTML  1@ (,8 + $ 8 ! 8F •
$ (,8 !
   0 # 
  ,8  K $  (,8 
 *O$  A
*$ •

  +G  ,8 *7)  1 *& %84 (4 
$   1 *8# J •
(  P0 ! ,QR 5  A2

Universal Knowledge Solutions s.a.l 4


: , 
, 5     I2 (4 &       I2 (4 * (,8 %  3, & •
 
  , + ! 5 ,  $  + 04 .5  8@ % 4 5  *7 C
* 2 !
   I$ !  # $# ! %$ 5, !.  4 *  

5, 3, (4 *,  $; '  *$ !)  


(,8 5#,  5, 2 
.('#   8
5$# + 1 ,+    8      + ! SQR 
  5? %8 
 •
 $# (,8 % @ T 5$#  *


   B$     2 , + 04   8 !+ >  & •
 view source   C  + I0) I    <A
+  >  

H T  
  5,+2 $  U I2   ,8 *
 ('# 5  
.!+ *+=

(2) '" ()  )
 ! %& 

:" ()  )
 !

:
) 3 
*7 C   5     (4 * L 
 *  +L 1  L
.5  8@ % 4 5 

  ? 5+ < 2    . # '# I2 1    @ HTML 5$#     L
.
   /0. + ! 
* ?= # 8 V HTML  . , *  >     1  & L
.<2 7+2  
 
   B$ *
 
  

:
4 
8  *& ,  > W   
 
   ! *8#  ,8 F L
.*8# *+

Universal Knowledge Solutions s.a.l 5


.
   /0. 
 5 ,8 A 8  *$ L

" ()  )
 ! 52 " 4   

: 
 
    ! SQR 5  =2 

PERL •
ASP •
ASP.NET •
PHP •
ColdFusion •
JSP •

5?, 2   , 
  5? (,8 <8  
 
    B
<  
6 (  A=4 (,8   + K $ Shell script  Perl  C *7   ,  
@ .  *,   , ! 5  * $ (Common gateway interface) CGI
I
+ K $ V  /0. 0 #  ,8 8 *J .    C ,8 * I0 * ?= X +
.     (4 0 # VW C


%< = .0 # I


K $ PHP  ASP *7 5?  ! 3,+ B 2 5   <7 $ B

 SR  * A   4 


  5$   8 2   *@ 
. 

: 
 
    ! SQR 5  =2 

  572  +   W   


   +   /0.  
 :PERL •
6 6 6 56$ CGI V 6 +  *  !. *
 0. !  8
*+=6 6   !  !. 9 $ *; 
 ! % +   +- < X APACHE
.PL $;   /0.  ! 
   5#, 0G .    ! !2

Universal Knowledge Solutions s.a.l 6


Java script *7 5?  !. 5 +  + = *@    /0.  B
:ASP •
.ASP $;   /0.  ! 
   5#, 0G .VB Script 

68 (6,8 56+  5 +  + = *@  < 2   /0.  B


:ASP.NET •
/06.  ! 
   5#, 0G .".NET" *8 4 8 K$> % 
 
.ASPX $;  

6  Z+ !. (Open source) $#  5    + .  B
:PHP •
   *@  1 $   +[ \#- %    1   +4 K $  ASP
6$; 6  /06.  ! 
   5#, 0G .  $#  + < X 5

.PHP

 8 Macromedia + =    !     


  !. :ColdFusion •
% 4 6X  7+2 1 * 8 *8 W   7+2 (,8   /0.  . 
 
 
.CF $;   /0.  ! 
   5#, 0G .5  8@

7+2 (,8   /0.  . 


 !
   A 
? (,8     !. :JSP •
6  /06. 6 ! 
   5#, 0G .(Windows/Unix/Linux) *8 W  
.JSP $;

6 7  89  "

:Apache  •

:IIS(Internet Information Services)  •

Universal Knowledge Solutions s.a.l 7


:Sun Java MicroSystem Web Server  •

:Zeus  •

:Apache "
5 (,8 <
 / 1   Apache software foundation C@  \# X Apache  
.Windows Novell Unix Linux *8
C68 php perl *67 6
  56? 6  , C8 :  +0 %  W  7+  0. 1
\# $ (,8 /  (4 - G 5$# *+= +$ 5 +- /  TLS  SSL] 5&+ ,
< =6 < 6=  5 7+2   0.  .U 2 *2 %  C ?7 
 C $ /  ' 
.2005 8 5A$4 $ ;- (,8

IIS(Internet Information Services) "


* !  W   5  8
 8 % 8 . Microsoft + = *@   0.  B

Windows 2003  Windows 2000 * ?= X  + < $   0. 1   .Windows * ?= X (,8
Windows XP pro server
B6@> 6 IIS 6 R  .FTP, SMTP, NNTP, HTTP/HTTPS 5 IIS 6.0  $  
6 <6 96    !  $ C ($ C+  =&  = K $  Apache 
56$ *+6= (6,8   6 B
 IIS 7.0  
  ! 5 ?7    
 B
@ . > !$
.5+ /0. 1 * ! +2   9   *# 5+

: Sun Java MicroSystem Web Server "


62 W  0.   .SUN ONE < $ (8R Sun MicroSystem + = *@   0.  B

.% +  * 5  < C,


     8
8 + JSP JAVA 5   ! 5 , 5     ! . * 5 ,T2 (,8  
.CGI 5  PHP ASP 5 

Universal Knowledge Solutions s.a.l 8


:Zeus "
5 =8 0 8  K $  (>   *$ . Zeus technology + = *@   0.  
. 82 9, UNIX *8 5 (,8 * 

IIS " 
8

:
8   :
4 5   "

6  'R <;7 . 7 ! IIS    5


$,  5 8  ?  +G L
.IIS 6.0   8 (2 $+ P4 V 5 ?  512  2 % +0
.!+= *& W 584   8 30 TCP/IP 5&+  ,W8 5 7  +G L
.NTFS 5#, X  CW  IIS   ,   84 L

:
8   "

16  0. 5 7   B$[+ IIS  Windows * ?= X  5 4 %8 
:  *$ 

.+$ $    7 Start  ? L1


   *^#F Windows 5+ 4 2 4   $ V  4 2 4    L2
.IIS
.Details  (,8  *;  5 7 5 W
  + L3

: -.

*6,   2  X +$ $ 5    Administrative tools  2 (,8  X$;
.IIS (4

I 6
I0 ,    INETPUB  ,
 4  ,8 < W, I
C2 < 2 X$; +
.C ,8 IIS 5 7

Universal Knowledge Solutions s.a.l 9


IIS " )  ; ()

:  W @  /2 *+= X + IIS % 4 


 +

6 %6
2 %8 (,8 2 
 # (,8 , IIS 5  X[   >  o
.    W  5,
 5 /0.  , 5 (4 - +=
.5,
 /0.  %$ 5#,  8 #   # C  X I0  >  o

+ + .  + C,8 (4 4 FTP + SMTP + *   % 5 IIS 
6 >   8 Pause L Stop L Start 5    5  I2 * # 9 4 * #
.5 /0.    2 (,8

: -.

.5>  = W@  Property   (,8  IIS    W, 58-  +

IIS 52  <= 2 4

  HTML 6 5$# W7 I$ 5,


 A=4 (,8 1@  !  > % +# 
IIS 6 ( . 
 2  
 * ! 
   (4 - . =
.  ,
   B$     '# 5, * I0   
Universal Knowledge Solutions s.a.l 10
56,
 -  H IIS  + .!W, ! W  ,
  wwwroot  < W, <,
 IIS Z=R
.  1@ 5$# W7 I$ ! 5,
 %
= 0
5,
 /0. *+= K $ .  4 B 2

(64 6 ,    584  $R  W, $# 4      $# = !#+
    4 * !  '# + K $  584 #  $R !W, ,

. C 8 < W,

'  2 ) 5%

A=4 + !W, ! W  ,


  %$ T 1@ 5$# (4 '# ! * +
.! & ,
 ( 

<6 W   B6$ T C+  T  !W, ! W  ,


  B$ CG+ '#, ,
 X
.C

06. (4 *,   C I0 & . (   2) *   !  ,
 *+ 3,
.,
 0  ! $ !W  #   @2 %< 8 +  ,


:  +0   %8   & 5,


 J

.,
, ! $ !W  #   ,# 8
$  + (,82 2 
 L1
L  (,8 H + (4 + L < W   5#, *  ,8 *
  % 4  ,8   L2
.5$#   , ? I2  & ,   ,8
.!W  #   @2 C+ ! &  +0   L3

<= 2 4 5 2 ) 2;

Default   (,8  >     5$#  8


   ? !  ,
 -
V6 * ?=6 (4  , /0. IJ .Virtual directory   New W   7 Website
.  & 5,
 A=[ 

M,
 0. (4 *, SQR  &  $ ,R o
Universal Knowledge Solutions s.a.l 11
M  (,8 ,
 0  !W  # 1@   $ ,R o
.,
 0. 5 $ * 5 $;  $ ,R o

I06 ! $ !W  # ,


  HTML   9, 1 +[ ' 58- /0.  
(64 *6 6+ K $   '#   8 C  +[ '  ! & ,
 C,7
.URL !    $  % =  $# B$

:*7

+= (,8 *   myweb  !  ,


 (,8 test.html $# (4 * I

:!    $ + 10.12.17.5 :IP  *$ 

http://10.12.17.5/myweb/test.html

6$ '6     http://10.12.17.5/myweb  1  DNS    + 0[


:*+=  !   

http://mydomain.com/test.html

Universal Knowledge Solutions s.a.l 12


58 

: 
XHTML ! P0

:   
.* .G %84      *$ ! *$ * 4 K$  @  8 % =G # P0

:!"
XHTML ! P0
!? . 
 
    (,8 , 5     > *8# 
 P0 ^ F
.#, . 8 P0 ,
 /0.

:  # $%&
:(,8 *# 0. !  9 
XHTML 8 $ •
XHTML ! P0 •

XHTML P0 8 •


  *$ o
 & *$ o
 > o
 # *$ o

' XHTML 5% 

Universal Knowledge Solutions s.a.l 13


 ,    = 1 <  HTML  A C B
HTML4.0   8    8 % 8 .
8 5 =G, ' $ * (,8  +  $# % =G *+ ;T4  $ 5 =G + ,2  $  XML
.. T Attribute=”Value” *7 5#  @  $ (" ") :*#  5 =G  
 ! '

XHTML 52 >?

:>?  @ A
!6 P0 ' . ,8# 7+2 HTML 5$# *
(4 9   H  G P0 9_ F •
  (4 5  /0. * 4 HTML $# ! %$ *$  5  1   $#
 
 I
 K $
68 *6+ A = 1  X  P0 (4   K
) $ *$  P0  ,8#   P  •
 
 <  5, *4   +̀   2 2 ! +4 ; X (4 2 +=

:>? 
2   2 2   *4 *$ *$ /0. + 2 + . 7+2 2 *4 *$  P0 + •
 W  ($ 2 W@ 2    5 
<form> </form> :  =G  %< $ P0 8 + •
* 6 (, .P0 8 (,8 %    &   B 2 HTML 5+ P0 I$ •
6+ + .(P0 *$ A*  # + \ = ! 8) <  < I$ 2 P0, + *7
! 8 . T 2 JavaScript ?, +   
 
   (,8 I$ 2 P0,
5     ,8

6  68 (64 2 6 
  (4 *$ 5  '# * R 
, P0 * 4 8
:I , P0 8 ! *+= R .  
 !
   (4 2 ! +4

Universal Knowledge Solutions s.a.l 14


Method  :>? 

: $ # /0.  a F .HTTP , * 4   5  * 4 ,2 # /0. $
2   (4 5  * - '# C
 I
K $ :POST  " 4 >?  L
. (4 *
S R  HTTP ,     T2  ! +4   8 (4
2   (4 5  * - '# C
 I
K $ :GET   " 4 >?  L
*
S R  HTTP ,  URL $R (4 9 9 $ ,, *+= (,8 ! +4   8 (4
. (4

  *7 HTTP , * - B >      3. POST  GET !  (4 -
  POST  GET   1 < $ * + Connect Trace Delete PUT
.   .   >  # <$&

Action  :>? 

2 + 04 ,
S R  5  C 4 * 2
I0   , Action # $ •
 !
   (,8 I$ $# URL $ 2 ! +4   8 #, %QR   +
. 

* -   8 Action # ! $  (4 * * -  ,8  •
Universal Knowledge Solutions s.a.l 15
.Submit

:1 8
<FORM METHOD=”POST” ACTION=”SK@scs-net.org”>
… Content
</FORM>
$   8 (4    +   4 5  $ Submit  ? 8 P0 0. 
.SK@scs-net.org *7 !

:2 8
<FORM METHOD=”POST” ACTION=”getInfo.aspx”>
… Content
</FORM>
 (,8 getInfo.aspx 9, (4   4 5  $ Submit  ? 8 P0 0. 
.,
S R  5  
  !
   I$ I0

:3 8
<FORM METHOD=”GET” ACTION=”Test.php”>
… Content
</FORM>
$ (4 5  [ 30 Test.php 9, (4 * [ Submit  ? 8 P0 0. 
sami !. *$  @ 5+ name !.  4   *$ B$4 5+ 0[ $#  URL
:! *+= * - 8 URL $ X
http://myDomain.com/Test.php? name=sami

 :>? EncType

  @ # /0. 0G .P0 5  * 4 8 SQR     EncType # $ •
5     /  B
5     ,2 96a   . MIME   2 
. 
> 9 $  ! *+=  #,

*7 *  (, .MIMEType/MIMESubType :! $ (,8      $ I



:!, + EncType #,  W,   8 aR I0 !W,     X
<Form ENCTYPE=application/x-www-form-urlencoded>
Universal Knowledge Solutions s.a.l 16
!    (4 5#, * 4 , ! 3, 8  P0 1 
     ', K $
:     I

<Form ENCTYPE=multipart/form-data>

AcceptCharSet  :>? 

# !. P0 !   \ 9 $ W@ AcceptCharSet # $ •
! UNKNOWN # /0   W,   + .5?, % P0 ! <   
.P0    !  9 $ W@ #  (4 =

   @ *+= (,8  #  @ 1 + 9 $ W@  7+2 & 
$ 8 •
:! *7 ! *$ . + ,#  , I

<Form AcceptCharset=”windows-1256,iso-8859-1”>

Target  :>? 

9  -  8 # /0.  @ F . > % 5$# W  ! Target # F
(, .(P  I2  
 !
   82 *$ !) P0 * 4  
- C  X I0
!  4  1 K$ P0  5  *- 
$ 8 # /0. F *7 * 
. H 4  K$ 
 U
& 
$ 8 HTML $#

:  target # 0G


.  % 
%0 ! P0 P  %84 I
 :“_blank” •
.P0 I$ I0 - #  P0 P  %84 I
 :“_self” •
.P0 I$ I0 N > -  P0 P  %84 I
 :“_parent” •
.B > 5 - *+ 4 1 ! W  -  P0 P  %84 I
 :“_top” •
:8
<form action=”SomeThing.aspx” method=”POST” Target=”_blank” >

:ONRESET  ONSUBMIT B9

Universal Knowledge Solutions s.a.l 17


.submit  ? P0 * 4 8 ONSUBMIT K$ 0 # I

. reset ? P0 5, A?4 8 ONRESET K$ 0 # I

:8
<form action=”test.aspx” method=”POST” onsubmit= ”window.alert(‘submitted successfully’);”>
“submitted successfully”   P0 0. * 4 8  X
 "&  :>? 

5# 
 04  'W = !  $ = @ ! 3, (,8 P0 K$2 5#  &
:!,     +0 B 2 K$2

:5# /0. 

.P0,     $ # /0. SQF :ID L

  _ R  CSS 5#,  > * T  *$ ! # /0. SQF :Class L
. 7 #  Style % =G
. 7 8   !   I
2 9  % =G /0. SQF :Style L
1   X- # /0.  @  '#  # K $  8  $ SQF :Title L
.   % G# =J   B   /0. I$

:K$> /0. 

   >   8 K$ 0  %QR  W


- 0 # I
ONCLICK L
  >  P  8 K$ 0  %QR  W
- 0 # I
ONDBLCLICK L

  >  ? 8 K$ 0  %QR  W
- 0 # I
ONMOUSEDOWN L

 >  8 ? $ 8 K$ 0  %QR  W
- 0 # I
ONMOUSEUP L
 
 % G# =J 1 8 K$ 0  %QR  W
- 0 # I
 ONMOUSEOVER L

Universal Knowledge Solutions s.a.l 18
 % G# =J 3 $ 8 K$ 0  %QR  W
- 0 # I
ONMOUSEMOVE L

 % G# =J P  8 K$ 0  %QR  W
- 0 # I
ONMOUSEOUT L
 .$ ! $
 \# $ ? 8 K$ 0  %QR  W
- 0 # I
ONKEYPRESS L

  \# ? 8 K$ 0  %QR  W
- 0 # I
ONKEYDOWN L
  \# $ 8 K$ 0  %QR  W
- 0 # I
ONKEYUP L

>? 
:8

<form method=”POST” action=”Test.aspx”


target=”_self” ID=”myForm”
class=”normalForm” EncType=”multipart/form-data” dir=”ltr”
onclick=”window.alert(‘you clicked the form’)”>
… Contents
</form>

5  * 4 ! POST   (,8  P0 9a R HTML  *7 0.   •
* 4 I
 R 
 <
  < I$ 9. 9,+ test.aspx 9, P0 $ •

, C 4 5 
C  X I0 - #  (test.aspx 9, 0 # 
+) P0 0. (,8 
& X •
“_Self”    P0 > P0
P0 0. (,8 “normalForm”    I
 “myForm” -  P0 3, •
% =G   7 #  2 CSS  7  < 9   0. + 2  &)
(STYLE
9, B$ * R P0 2 !  “multipart/form-data”    P0 0. ! SR •
 (4
P0 (,8  8 “you clicked the form”   X •

  :>? 

Universal Knowledge Solutions s.a.l 19


:!,      P0 !   *$  U2 %8  +

:! "; 

  *4 *$ 9G .P0 ! < *$ U2 7+2   *4 *$ F •
 $  *-  b  *$
 4 \ 9 $ 8  $ I
 Size #  *$ 0. 
$  $ I

9 $  maxlength  Size  K $ maxlength #
5 $  I
$ /0. ! .Size #  +2 maxlength # + 2 + •
+ A72 ! *$
*$,  W,  @ A8- Value #  + •


 
   (4 G
, 0 5; U +$, % =  H  2 HTML ! 
 &
8 *$ ! G *W  X4 5     
 
   (4 2  
., 5   2  1  

:8

 9 $ 10 * +  test !.  W,  @ (,8 I$ mySample  ! *$ A=-
:!  + < $ 40 c, 9 $  (@2

<input type=”text” name=”mySample” value=”test” size=”10”


maxlength=40 />

  :>? 

: 4  "; 

.,
Q R 9 $ !# U@   1     *$+   *$   0. SQR •
+  <T I0 U 9 $  8 <8 B * 9 $  J  == (4 X + & 04
“*” 2 "O" 9 $ $2
Universal Knowledge Solutions s.a.l 20
& 0. + == (4 X 2 *-  ,8 A72 (“*” 2 "O") U 9 $  X4 I

A72 2 *-  ,8 C ,8 I
 I0 
 (,8 , V ,  R + 9 $ 2 !
. (4 5  * 4  ,8
:8
<input type=”password” name=”myPass” size=”10” maxlength=25 />

  :>? 

:$ 4 "; 

 (4 C 4 I


($ 9,   ,   *- *$   0. ' •
9, (4 *, '# C I0  8   ! B$ 9,  + •
9, 8 <7$ 5,
   ! 8  (4 < 4 ! *$  X[  0.  •
,
   8 P0 5  * 4 ! POST      & *$ 0. *  •
GET
 @ $ .5#,    * [ \,  0. 1 Accept #  + •
  4   5#,, MIME  Accept #

:8
<input type=”file” size=8 name=”myFile” accept=”text/*” />
9 $ 8 *$  8 + K $ myFile [ 9, *$   *$ A=4 I
*7 0. !
*7  8 # C2 1 
 Text   5#, *$ 0. * K $
.(text/html, text/css text/plain)

  :>? 

: 49 #  ! "; 

.<TEXTAREA> % =G  30 >   *4 ! *$   0. 8

:% =G /0   5# .2 

Universal Knowledge Solutions s.a.l 21


> 8 $ ! Rows # L
%8> 8 $ ! Cols # L
#   + . $  8 
 8 9#;   ,@ $ ! wrap # L
9# *  ! “off”   8 K $ “Physical” 2 “virtual” 2 “off”   B$4 0G 2
5  (4 * I2 [  &  +  9# 5 7 ! “virtual”   8   
, 9# *+ 8 ! $  * 9  ! “Physical”   +   4 I
!
.P0 * 4 8 5  1 C 4 I


:8
<TEXTAREA rows=”10” cols=”6” name=”myTextArea” wrap=”off”>
… This is a test
</TEXTAREA>
0. ! I
 myTextArea  9 $ 10 U#  9 $ 6     $ *7 0. Z=R
. 9#  *  P0

 "  :>? 

:  > 50 *$ 9  0. 5$ P 

::  #


C, # 4 2 C, # + 8 *$   0. Z=R •


/   8 X % =4 C  X 1  8 % 8  0  I , *+= + •
% =4  2 X !   @ !. % R   @ * 4 I
P0 * 4 8 •
,
S R  5  V I0 !
   + A72 $ ! U 0. 02
0 .X
Value #, %R   (,8 *$   0. !   4 I
!    •
(4 “Checked” # 4 8 30 P0  X4 8 < W, $ *$ * # + •
 U 0  F 5# + 8 ;  +  @  2 “Checked” # 0G & .% =G
Checked=”Checked” : + # -    @ 5#

Universal Knowledge Solutions s.a.l 22


:8
<input type=”checkbox” value=”test” name=”myCheck”
Checked=”Checked” />

 "  :>? 

:    *&

  $     + K $    5@ 5   *+= *$   0. *+= C= •
%$ 8
 (4 ! ! *$
#, %R   (,8 $ 5  1 *$ !. + P0 .  !    •
Value
 W84 “Checked” # 4 8 30 P0  X4 8 < W, $ *$ * # + •
$ 5  $ ! *$ . + “Checked”  

:8
<input type="radio" name=”myRadio” vaue=”option1” checked=”checked”
/> first option<br>
<input type="radio" name=”myRadio” vaue=”option2” /> second option
<br>
<input type="radio" name=”myRadio” vaue=”option3” /> third option
R  ; < “first option”   * 4 I
K $   
 /;82  0 # 8 X
:*+= !

 "  :>? 

:  " C=

:W  2  A=- <Select> % =G  & W@  •


 W o

Universal Knowledge Solutions s.a.l 23


, , W o
5   W@  5   %8 2 $      ,8 0 # ! 8 ;+ 8 •
W    *+  I
K $ <option> % =G W 8  $ I

<option></option> % =G 
6 $     ;
< $ P0 * 4 8 name # $R  *$ * 4 I

*7 *$ * $ I
   & $ ! 2 . $    @ *$ ! option
,#    8 # 5   W@
! 5   %8   +4  $ “multiple”    W84 multiple # 4 !#+ •
   & W@
 ? W ! 8  7+2     &  * # 8  1  •
# *  & W@ [  /0. * # 8 *$ ! 2 ., 5   (,8  CTRL
5   8
   $     ' K $     2   * !  ]
# /0. (4 F 8 &N ,  & W@ U#  Size #  @ +$ •
 W@ (4 W /0. *$ W  $   X4 I
”1”  
  A$& ;   W 0G 4  & W@   +$,  # 
 & •
9 $   +>  $
.A8[ Selected #   W, 5    8
2 !W,    $ I

  5      *+ option % =G  30 “Selected”  
% =G  30 %$ 5   W@  5     8  58
 A=4 + •
% =G /0.   8 # 8
 5   1 
$ <Optgroup>

:8
<select name="select">
<optgroup label="Syria">
<option value="1">Damascus</option>
<option value="2">Aleppo</option>
<option value="3">Lattakia</option>
</optgroup>
<optgroup label="Jordan">
<option value="4">Amman</option>
<option value="5">Alakaba</option>
</optgroup>
</select>

Universal Knowledge Solutions s.a.l 24


# $ # $
Size=1 Size=7

 *9 :>? 

: P0 (4  4 + !  d  2 U2 7;7 3.

:>?  %D ; 4 3  *&

! $ 9, 8  
 I
 ($  (4 P0 5  * 4 ! * -  8 •
  Method # ! %$    30 P0  Action #
P0
type # (4 “Submit”   4  2 (,8 input   0.  •
# X #  G button % =G  + •

:*7
<input type=”submit” name=”test” value=”Send”>
2
<button type=”submit” name=”test” value=”myValue”>text on
button</button>

*@   4  !   1 


 *$ b 4 (4 Reset P0 * .G %84  IJ •
 (4 5   2 * 4  
 @ 4  =  0.    $ button % =G 2 input % =G  + •
Type # (4 “Reset”

Universal Knowledge Solutions s.a.l 25


:*7
<input type=”reset” value=”reset”>
2
<button type=”reset” >text on reset button </button>

 *9 :>? 

:     *9

%  * -  * 7 8 P0 (,8  


A#4 9   >  U 0.  R •
Type # (4 “image”   4 1 input % =G * I

(4  (,8 %  9, ,2 !  [ SR %  9,  $ I

Src #
:8
<input type=”image” src=”./images/myImage.gif”>

 *9 :>? 

:@ E9 #   *9

] ($ / 2 8 #, %  T2 50  2 A=4 !  0. 8 •
*#   *#  $ K$>   >   0. ! I

 
 !
     > /0. , •
type # (4 Button   4  Button % =G 2 Input % =G  > /0.  •
:8
<input type="button"
value="Please Don't Press This Button"
onclick="window.alert('any message.')" />
2
<button type="button"
value="anyValue"
onclick="window.alert(any message.')"> 'Please do not press
this button again.</button>

 X[   


 !
     (,8 ? K$ (4 % =-  *7 ! B

Universal Knowledge Solutions s.a.l 26



   @ 0G Button % =G 2 ! Input  Button  ! W  9;& +  .
   (,8 
  $  input % =G $ ! 2 % =G $    (,8
.% =G /0   value #

"  :>? 

: " 
0. 9 K $ ,  W  T  + T P0 !      # *$  •
P0  ' *$ ! .  X4  LP0 * 4 8L 5,  (4 *$  

: $ ! %8 *$   0.  R •


I0 !
     /0.   # K $ , & I2      (4  @  L
 
 5  V
 A#4  04 .   , > ,  W  T ( 2
5,  L
2 2       $   /0  , R  5,

2 .Type # (4 “Hidden”   4  input % =G *$   0.  •
Value # (4 %QR   !  P0 * 4 8   4 I
!  

:8
<input type=”hidden” name=”myHidden” value=”value we want to hide”
/>
:  !. /;82  I$ P0 * 4 B
*$ !  (4 * !   $2 +
myHidden=value we want to hide

  

& @  .register.aspx 4


$ 0; (4 3 5  2  <) 0 # >? F7;  
:5  7 H  >?

Universal Knowledge Solutions s.a.l 27


:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1">
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>

<body>
<form action="register.aspx" method="post" enctype="multipart/form-
data">
<table width="340" border="2" cellpadding="0" cellspacing="0"
bordercolor="#FFFFFF">
<tr>
<th width="185" bgcolor="#666666" scope="row"><span
class="style1">Login Name</span></th>
<td colspan="2"><input name="login" type="text" id="login"></td>
</tr>
Universal Knowledge Solutions s.a.l 28
<tr>
<th bgcolor="#666666" scope="row"><span
class="style1">Password</span></th>
<td colspan="2"><input name="pass" type="password" id="pass"></td>
</tr>
<tr>
<th bgcolor="#666666" scope="row"><span class="style1">Full Name
</span></th>
<td colspan="2"><input name="fullName" type="text"
id="fullName"></td>
</tr>
<tr>
<th bgcolor="#666666" scope="row"><span
class="style1">Sex</span></th>
<td width="64"><input name="sex" type="radio" value="male">
male</td>
<td width="81"><input name="sex" type="radio" value="radiobutton">
female</td>
</tr>
<tr>
<th colspan="3" bgcolor="#666666" scope="row"><span
class="style1">Address</span></th>
</tr>
<tr>
<th colspan="3" scope="row"><textarea name="address" cols="50"
id="textarea"></textarea></th>
</tr>
<tr>
<th bgcolor="#666666" scope="row"><span
class="style1">Email</span></th>
<td colspan="2"><input name="email" type="text" id="email"></td>
</tr>
<tr>
<th bgcolor="#666666" scope="row"><span class="style1">type of
membership</span></th>
<td colspan="2"><select name="select">
<option>MASTER MEMBERSHIP</option>
<option>NORMAL MEMBERSHIP</option>
<option>GUEST MEMEBERSHIP</option>
</select></td>
</tr>
<tr>
<th bgcolor="#666666" scope="row"><span class="style1">picture
File</span></th>
<td colspan="2"><input name="myPicture" type="file" id="myPicture"
size="10"></td>
</tr>
<tr>
<th colspan="3" bgcolor="#666666" scope="row"><span
class="style1">interested in </span> </th>
</tr>

Universal Knowledge Solutions s.a.l 29


<tr>
<th colspan="3" scope="row"><select name="select2" size="5"
multiple>
<option>Sport</option>
<option>Education</option>
<option>shopping</option>
<option>Gifts</option>
<option>other interests</option>
<option>___________________________________________________</option
>
</select></th>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td colspan="2"><input type="reset" name="Submit2" value="Reset">
<input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>

9 F*) – B8 

: 
GET  POST    HTTP ,

:   
.
/
4 *+      ,

Universal Knowledge Solutions s.a.l 30


:!"
/0. ! !? .POST  GET !   .2 HTTP 5, * -    8
 (,8 HTTP *+  
GET   ;+  !  & 5@ #   HTTP *+  , 8  5,  ,

.POST 

:  # $%&
:(,8 *# 0. !  9 
HTTP 5, •
5, * 4   •
 & (,7  =  POST  GET !  •

: "
58

($   LO 6 8) (Learning Objects) 5$ 4 •

 HTTP GET   HTTP POST 1.1.1

B$4 4  +4 ^  “Method” # “Form” % =G,   A72  ,
!  +0
2 5  * 4 I
 9 + $ # /0. 2  +0 # /0  “GET” 2 “POST”  
.HTTP , * - F !  

. HTTP *+  , A


>   \ =    &   0.   #  #

:HTTP  

.5 > += (,8 5  *@ R !> !  *+  HTTP *+  R
)    ('#)     (
/ ,)  H HTTP *+   
( 

:HTTP 
Universal Knowledge Solutions s.a.l 31
.HTTP , * [ HTTP ,@ 2
A
> /0. !,     .! *+= ! X + A
>  8
  HTTP , +
.A
*+  ,$ ! 5, U <$& $

GET / HTTP/1.1
1

Connection: Keep-Alive
2

3 Accept: image/gif, image/x-


xbitmap, image/jpeg,
image/pjpeg, */*
Accept-Language: en-us
Accept-Encoding: gzip,

4 Content-type:application/x-
www-form-urlencoded
Content-length:23

5 Name=sami&type=3

 HTTP GET  HTTP POST


 HTTP

1   /  ($) 9a R

2    

3 ,   

4  +   

5  + 

:!,  HTTP , 9G

, I0 (Method URI HTTP/version) %   http ,  *> A


 + .1
0.  !@  *7R .Method    (URI)  9a R 8   $#
. *+   (HTTP/1.1 A
) ,  A

5, 2 !$ f + 8 5, $      ,  !7 A
 I$ .2
Universal Knowledge Solutions s.a.l 32
0.   HTTP , * 4  2 + K $ I 
4 T A
 0. R .!$ *&+ 
.A

 , * R  , 5, (,8 ,    (8 I0 K7 A
 I$ .3
 HTTP , * 4  2 + K $ I 
4 T A
 0. R .9   ,S R 5 
.A
 0. 
, 5, I$ . C [ U = 8   +    (8 I0 1  A
 R .4
I2 * 4 8 *$ ! I   T A
 0. + ./     /  C   + 
.  +
. *$  @ *7   [ ,  !   I$   + 
> A
 *7 .5

POST & GET 

!   I
 !   (,8 I$ C2 
 HTTP , + A
>  (4 %
:     B$4   /0. 0G .5, * 4

  (4  5  * 4 I


 URL $ %$  7 , I
:GET
. #     URL $
  (4  5  * 4 I
 URL $ %$  7 , I
:POST
.5    I2 !    + 
  A
  5   1 URL $

     HTTP *+  8 +  XHTML P0 1 * A72   . F
:  +0 B >

    + , 0. (,8 


 + GET C  I0 ,,  ,  :HEAD
 HTTP 
    ! %
 5, (,8 *$ !   /0.  # .
I2 
. , (,8 
- 8 %< 8  , I
!  7  30 !  
 B$ *+ * (4 
$
.& %  !. URL $  4 =R  7 90$ F :DELETE
5,     +F K $ .
+ , # %84 I
 , * 4 8 :TRACE
.*  , B$ (,8 *$ ? I2   2 , (4   5  #  !

Universal Knowledge Solutions s.a.l 33


.   *8 &   +    8 ! HTTP   W@   :OPTIONS

GET & POST

:!,  %8  I    P0 5  * - GET  8

< + 5  /0. 


$ + &2

 ^  1 , R  5  *$ &2

:!=     8 9,    @  8 % 7+ < 2 GET SF


<a href=”test.aspx?x=10”>click here</a>

:*$ ! P0 5  * -  POST   2


F  + 
$ 5  * 4  2 •
$ P0   * ! 5, 5+ 04 •
 HTTP , * 4 GET  HTTP , * 4   # (,8   2 
:XHTML P0 !    *
) +   '    & POST

:!,  %8  I    P0 5  * - GET  8


!X8> 
$ $   4 + 5  
$
^ > < X < + 5  /0. 
$ + &2

URL 6 I2   $
 $  X =+ + 5  /0. >  ^  1 , R  5  *$ &2

  8

04 *7 *  (, .!=     8 9,    @  8 % 7+ < 2 GET SF
+ click here , +  , (,8  8 test.aspx 9, (4 X=10     2

Universal Knowledge Solutions s.a.l 34


:! *+= (,8 ? 
<a href=”test.aspx?x=10”>click here</a>

:*$ ! P0 5  * -  POST   2


5   + 
$ (,8 I$  1  2 9, *7 F  + 
$ 5  * 4  2 •
  $  .  X4 + & K $ $ P0   * ! 5, 5+ 04 •
  !
_____________________________________________________________________
____

!7 A

: 
ASP.NET (4 

:   
.V 5 7   52   W  *8 4

:!"
5 7  # + (,8 *# 0. ! 9  . 
 
   *
 ! %W  5   ASP.NET 
.Visual Studio.net  W  (4 -   /0   * 4

:  # $%&
:(,8 *# 0. !  9 
ASP.NET 8  •
.Net * 4 5 7 •

Visual Studio.Net 5 7 •


ASP.NET     W    •

" ()  )
 ! 0; 
ASP.NET " 4

Universal Knowledge Solutions s.a.l 35


 
   + ! % 5  .2 $2 8 *7+ ASP.NET 8 K $ (,8 !,    +   
.  * # 8   /0. 5  8 ,+ +  

:ASP.NET  C

8
.NET * 4 5 7   $ I0 # 9,  5 7 $ + 04 .<  *  ASP.NET  W  5 7  R
..NET 7 5#,  
 ,72 5 7  +[ , 5   5 7 V   .ASP.NET  I0

  /0. (,8   .8  & Windows Installer 5+  K $ 5 7 V , 2 +
:!, + $ == X 2 + 04 5 7  ,  ;

 + C 7 *>  + I 


4 T +  I0 MDAC 2.7 + 5 7 %   *4 %0 /0. =
.ADO 5  8@ (4 * 52 1 * #,   

ASP.NET  C

8

Universal Knowledge Solutions s.a.l 36


:*+= (,8 !. 5 7 V %0 X 5 7 A 8

.,7>  8
 (4 4 
   52 5 7  +4 V 

1 (5 +  5  %8@ 3 $) MSDE + !W, 5 7 I


,7> 5 7   *$ !
.,7>  A
+  
 5  %8@

.5  ? 18 ,72 I2   .NET *8 4 


$ c,

ASP.NET  C

8

Visual Studio .NET C

 W  *.4  ASP.NET 5#, * ?= + <& < =   Visual studio .NET 5 7
^ 2  T 
A> 4 5 H +$ 8  5
 *;  30   ,8 A72  8    C  3,
.B > 5   7+ (4 - ?, 5 # !+0 $ 5 H * ?= W  8 


:Visual Studio .NET 


8
:.NET *8 4  ! 5+  8
 Visual Studio .NET ! 5 7 V 57 •
MK$2  I2 2 MS installer 2.0  o
MMSFront page 2000 web Extention Client  o
Universal Knowledge Solutions s.a.l 37
MW  5 7  ,  * ?= 5#, o
MInternet Tools (4 - Internet Explorer    6.00  o
MMS Data Access  2.7  5+ o
.Microsoft .NET *8 4 o
8  ,8 *$  < H   7 I
K $ * ?= W  ! %  57 $  $  ,8 5 7 V 0# •
.5 & *&  

Visual Studio.net 
8

  f ! *$ !. + #, 5? 1 *,  52 5 7 V ,  .NET *8 4   < X
U 
  !   I
 ! ?,   Visual studio .NET * ?= !#+ 04 3,  W  
 .NET * 4 5?  ? I2 1 * W   a  (,8 ,> 0. *a R ./J=4    
.*, % 
W  1 ,@G (4 
$

:ASP.NET 0 # Visual Studio .NET" 4


 ASP.NET WEB Application   !#+ Visual studio .NET  ASP.NET 5  
 A 3+  /0.  . W, 5$#  1  1@  , /0. Z=F .New project %0 5  
.  
  #, +$ 8    H

Universal Knowledge Solutions s.a.l 38


ASP.NET   *8 5; # (,8 +  Visual studio .net W  (,8 *  * # ! * 
.  W  8 X ?  ? 

: -.
.IIS  5 7 (4  
 
    + P$ ASP.NET 2 < 2 C    &

ASP.NET ?

 .  8  7+ (4 %  


  +  T  Microsoft    ! (> ASP  5 
 5?, 2  ?, /0.  *
 !  >  !.   W + ASP.NET  &  I0
.  (,8 5 
 & 
   
 2 
 
     +4 (,8 ASP.NET ?  •
MA> K $  %  ASP.NET *
 0 # A72 !
   # a#  (,8
M!
  , + 
$ *@G  8   0 4 ASP.NET  •
M , %
>    #, 5
 1 *  5+  8
 .NET 4  •
M    1   W  XHTML  XML 5   8 *;  ASP.NET  •
5$ ! *+= A> ,T2  , (,8 8  #  ASP.NET  %84 5

. ;2  ,8
. # *  9 X !
   +  W  ASP.NET  •
. @7  > 1 *  ,@ ASP.NET $ •
8  +  *
 VB.NET J#  C# *7 
  5?    .NET *8 4 8 •
.ASP.NET    %84 5?, /0.  ? IG 5+ 2 +$

7

(1 
 2 %$ %  9 = .0# 2 2 /
(,8 .0# 2  *+ + ) .Net Framework 5 7  ,8 0#
.  5 7 *$  (,8 <8

:09   /
8  ?2 (- •

Universal Knowledge Solutions s.a.l 39


:5  
8 0 B   K
4 •
• Windows 2000 Service Pack 2, if installing on Windows 2000.
• Microsoft Windows Installer 2.0
• Microsoft FrontPage 2000 Web Extensions Client
• Setup Runtime Files
• Microsoft Internet Explorer 6.0 and Internet Tools (this requires a reboot)
• Microsoft Data Access Components 2.7
• Microsoft .NET Framework

?  0 4  6   & .=3 ;  (" 4 1 ) B 


   " 4 4 ";  •
." 4 "  )  6 L 
8  

: 
4 M4 52 #
N O  5  
8   " P <
 Visual Studio .Net 
8  •

Universal Knowledge Solutions s.a.l 40


(-   3
 5Q B    # KR O #)  " " 4 H O S 
4  "  F(   •
. ) 8 

.=; Q 1 ) ; S 2 9 TA7O 8  A  " " 4O #) 0 8  "4  #  •
.6 7
 U   O :
 A  " Visual Studio .Net

Universal Knowledge Solutions s.a.l 41


:Visual Studio.Net 52 ASP.Net 
  •
(/;82 *+= ! .X) New Project dialog (4 .0 o
ASP.Net Web Application   o
 W, 5$#  8 1  1@ A I
o
:!,   $R 5
   5$# 8 +$ 52   ] + o

Universal Knowledge Solutions s.a.l 42


: "& 
8   •
.ODBC 5@ (4 *  +4  I0 :ODBC .NET Data Provider o
.(PDA 9.)  5
 8 1@   +4  I0 :Mobile Internet Toolkit o
.'#  %8R 52 :Internet Explorer Web Controls o

Universal Knowledge Solutions s.a.l 43


<
  

: 
 
 HTML +$ 8

:   
% =G     
+$ 8

:!"
3, .2   
 +$ 8  .  $# 5+ +2 +$ $ %  5  ASP.NET 5@
.5 
HTML +$ 8 .  /0.  A
(,8 9  ,
 /0. *; *$

:  # $%&
:(,8 *# 0. !  9 
 
 +$ 8 •
HTML +$ 8 *$ * # •

ASP.NET < .=3

5,
 *;  *$  
 
    # (,8   5,
 ! ,
h
.*
 0. ! %W  5  B$4 . 8 (,8 ASP.NET    ?  

: C
 ;

   5#, 1  L 
 
   * ?=  + ($L   &
.  & 5,
 $2  2 wwwroot ,
   (,8

:  < 2 +G 2  &


.NET* 4 5 7 L
IIS   5 7 L
ASPX 5#, (,8 I$ ,
  5#,, 0 #  $; A84  +G L

Universal Knowledge Solutions s.a.l 44


6) 4
ASP.NET  :8
:HTML 5 ,  I$ I ASP.net 2 I2 I$ & ASP.NET $# &
< 2 2

<html>
<head>
</head>
<body>
<p> this is only a test that contain html.</p>
</body>
</html>

$  C 4 *   ! C, ?=  7 (.ASPX) $;  0. X#$ 2 +
.C  !  

$# B$  X[ 9, 0.   .0 # ASP.net 5 , I2 *7 0. !  I$ &
.  (,8

5,
 *;  *$  
 
    # (,8   5,
 ! ,
h
.*
 0. ! %W  5  $2 . 8 (,8ASP.NET    ?  

: C
 ;

   5#, 1  L 
 
   * ?=  + ($L   &
.  & 5,
 $2  2 wwwroot ,
   (,8

:  < 2 +G 2  &


.NET* 4 5 7 L
IIS   5 7 L
ASPX 5#, (,8 I$ ,
  5#,, 0 #  $; A84  +G L

Universal Knowledge Solutions s.a.l 45


ASP.NET52 )
 ! " 4

:$ 5    8


   ASPX 9,  ASP.net  &

/8 B
K $ .ASP.NET  !
   $ <% %> % =G  •
:! *+= C (ASP.NET 9,) ASP  1   

<% the code goes here %>

runat # (4 server   4 1 HTML  <Script> % =G  •
:! *+= (,8 +  ' K $

<script runat=server>
The code goes here
</script>

7ASP

! 5,7 !  


 
   5   7+ % #  ASP  58
!
   1  <W  & + 0 HTML P    8 !
   *  +4 8
.C  P   X4   I0 + !

:8
<html>
<body bgcolor="yellow">
<center>
<h2>Hello W3Schools!</h2>
<p><%Response.Write(now())%></p>
</center>
</body>
</html>

! .   P   X4  !  ! !


   1 (4 *7 0. !   2 X$;
.f  5@ $

Universal Knowledge Solutions s.a.l 46


! 5,7 !  
 
   5   7+ % #  ASP  58
!
   1  <W  & + 0 HTML P    8 !
   *  +4 8
.C  P   X4   I0 + !

' ASP.NET ( = 5  23 

8   .8 P    8 !


   *  +4 8 ,+= ;
< $ ASP.NET 5@
.Server Control   (  2 a  9   +$

.  *    , + 5 =G 9  !.  


 +$ 8

: 
 +$ 8   2 U2 7;7 ASP.NET 
HTML +$ 8 .1
(ASP.NET    % 
U2 !. )  +$ 8 .2
 *  $ ! 8 +$ 8 .3

 $  
 +$ 8 .2  5,
 *; ,
 /0. A72 Gi$&  
ASP.NET ! K$>  #   %      &   0  A *@ + .,7G
.,72 ,T2 ! C >
!
   I2 2 ! !. SB9
 )
 (  (,8 
  5   7+ 
.K$ V  !
    0. (   K$ <  + 2
/0 # I

%   (4 /& ASP.NET ?   5  C


  A72 V  (,8
 30
 (,8  ! K$> % 
      +   
   1
.K$ V %< = K$

Universal Knowledge Solutions s.a.l 47


ASP.NET 52 B9

:8
:! !
   (4 X
<%
lbl1.Text="The date and time is " & now()
%>
<html>
<body>
<form runat="server">
<h3><asp:label id="lbl1" runat="server" /></h3>
</form>
</body>
</html>
:*J \   2 04
j /;82 $ !
   0. 0 #   (
!!!,& : <$ 
- +

!
   I2 2 ! !. SB9
 )
 (  (,8 
  5   7+ 
.K$ V  !
    0. (   K$ <  + 2
/0 # I

%   (4 /& ASP.NET ?   5  C


  A72 V  (,8
 30
:(,8  ! K$> % 
      +   
   1
.K$ V  !
   0 #  K$

!
   I2 2 ! !. SB9
 )
 (  (,8 
  5   7+ 
.K$ V  !
    0. (   K$ <  + 2
/0 # I

%   (4 /& ASP.NET ?   5  C


  A72 V  (,8
 30
 (,8  ! K$> % 
      +   
   1
.K$ V %< = K$

Universal Knowledge Solutions s.a.l 48


( 
  (
 5  B9 %&

Page_Unload Control Event Page_Load Page_init

  !"# $‫ﺡث ی* إ)('& ﻡ‬ ‫ﺡث إم  ا‬

‫اآ!ة‬.‫ ا‬$‫" إز ا ﻡ‬# ‫ه ا‬

:?   8 S  R   8 # 5A


- *+= ASP.NET ! K$> 5
 0G
Sub event_name
Event_handling _code
End sub

" ()  HTML  

/0.  ASP.NET 9,  X !   , html % =G $ !    J $
1 *$ 9, .  $#+ V  X4 7   *@  . # I
 I8 + % =G
.   # 
 , ,@ 5++  3, *F K $  
 HTML +$ 8

  4 % =G /0  runat # 4 !#+ +$ + *S F HTML % =G *

9 a R +  *@  <$&   I
K $ (ID) #,  @ A84  4 "SERVER"
.!
   * ?= 8  +$ 8 (4 *,

: % -.
8 %   (4 /& 1 <form> % =G   
 +$ 8 1 
X 2

2  ;8- 30 ID #,  @ runat #,   .  I2 +$ 8 % =G /0.
* +  0  % $ l 2  9   P0+ C *
P0 0.
. 
 !
   *@   4

:8
ASPX 9,  !=   U  +$ 8 8 '  @ *7 0. !

Universal Knowledge Solutions s.a.l 49


<html>
<body>
<form runat="server">
<a id="link1" runat="server">Visit sk website!</a>
</form>
</body>

.!
   ! X +  0   ID #, "link1"   A84 

% =G $ !    J $html 9,  X !   , ASP.NET /0. 
1 *$ 9, .  $#+ V  X4 7   *@  . # I
 I8 + % =G
+$ 8HTML.   # 
 , ,@ 5++  3, *F K $  


  4 % =G /0  runat # 4 !#+ +$ + *S F HTML % =G *

9 a R +  *@  <$&   I
K $ (ID) #,  @ A84  4 "SERVER"
.!
   * ?= 8  +$ 8 (4 *,

 HTML" () 

 /0. .2     


 HTML +$  !> 2 $2 2 
*;   /0. 1  ! 5 ]  '    0. A72 $ < . 7+2
.,7>

:HTMLANCHOR 5
#7  
  
.<a> % =G  . !=   A=- 0. +$ 8 *
:  0. *7 I0 !
   ? 5; .2 

ATTRIBUTE
  @  0. 5# 1 
 W@   S

  @ *_#Q R T 2 *^#  0. + $    @


DISABLED
!.   &FALSE

Universal Knowledge Solutions s.a.l 50


!=  ; !   ^$ HERF

 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2  


INNERHTML
(4  9 $ * $  & . HTML
0. ;T4 ' ! =G $  %84 2  
INNERTEXT
(4  9 $ * $  . HTML

 &  NAME

W   CSS  0. (,8    I


 ! STYLE

  !=  & B$ ' I


 ! 9  %0  TARGET

 & 0.  =J 3 $ 8 X 9 I0  TITLE

& 2 !W   0. + $    @ VISIBLE

ONSERVERC
, /0. (,8  8 /0 # I
 I0 1  LICK

:8

<script runat="server">
Sub Page_Load
link1.HRef="http://www.google.com"
link1.Target="_blank"
link1.Title="google"

link2.HRef="http://www.microsoft.com"
link2.Target="_blank"
link2.Title="Microsoft"
End Sub
</script>

<html>
<body>

<form runat="server">
<a id="link1" runat="server">Visit google!</a>
<br />

Universal Knowledge Solutions s.a.l 51


</form>

</body>
</html>

. google 1@ !7 MSN 1@ .$2 , A=[ 7  

+ 5 , 1  K $ $# B$ ,+   8  ,  !
   ,+
S 2 X$; +
.*7   ! Page_load K$ V
. 
 +$  W  @   H $ %  

HTML   


HTMLBUTTON   
I0  ? 5; .2  .<button> % =G  .  A=4 (,8 0. +$ 8 *
:  0. *7

  @  0. 5# 1 


 W@   ATTRIBUTES

  @ *_#Q R T 2 *^#  0. + $    @


DISABLED
!.   &FALSE

 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2  


INNERHTML
(4  9 $ * $  & . HTML
0. ;T4 ' ! =G $  %84 2  
INNERTEXT
(4  9 $ * $  . HTML
ONSERVERCLI
, /0. (,8  8 /0 #   I0 1  CK

  0G Server  


 +$ 8 2 $  RUNAT

W   CSS  0. (,8    I


 ! STYLE

Universal Knowledge Solutions s.a.l 52


& 2 !W   0. + $    @ VISIBLE

:8
.    *+  8 9,  , O X R  #, ,  *7 0. O X R 
:Page_load $# * $ K$   +$ 8  , ! K$>  2 X$;
Sub event_name (source as object , e as eventargs)
…..
End sub

.(7 $ !) onserverclick #, K$   @ A84 K$ V  K$   !#+

<script runat="server">
Sub button1(Source As Object, e As EventArgs)
p1.InnerHtml="You clicked the blue button!"
End Sub
Sub button2(Source As Object, e As EventArgs)
p1.InnerHtml="You clicked the pink button!"
End Sub
</script>

<html>
<body>

<form runat="server">
<button id="b1" OnServerClick="button1"
style="background-color:#e6e6fa;
height=25;width:100" runat="server">
Blue button!
</button>
<button id="b2"
OnServerClick="button2"
style="background-color:#fff0f5;
height=25;width:100" runat="server">
Pink button!
</button>
<p id="p1" runat="server" />
</form>

</body>
</html>

HTMLFORM   


.2  .<Form> % =G  .  
 P0 A=4 (,8 0. +$ 8 *

Universal Knowledge Solutions s.a.l 53


:  0. *7 I0  ?  5;

. 4 5  * 4   ! $#, !   $

ACTION
$ # A84  
 +$ 8 $ !

.<W  $ $#

.  @ 5# 1 
 W@   ATTRIBUTES

  @ *_#Q R T 2 *^#  0. + $    @


DISABLED
!.   &FALSE

2 $ 5  #=  $MIME. ENCTYPE

 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2  


INNERHTML
(4  9 $ * $  & . HTML

0. ;T4 ' ! =G $  %84 2  


INNERTEXT
(4  9 $ * $  . HTML

:5  * 4   $GET 2 POST METHOD

 &  NAME

  0G Server  


 +$ 8 2 $  RUNAT

W   CSS  0. (,8      ! STYLE

  !=  & B$ '   ! 9  %0  TARGET

& 2 !W   0. + $    @ VISIBLE

HTMLGENERIC   


*7  ? 5; .2  . 
 % =G I2 1 , C + 0. +$ 8
 0 

Universal Knowledge Solutions s.a.l 54


  @  0. 5# 1 
 W@   ATTRIBUTES

  @ *_#Q R T 2 *^ #  0. + $    @


DISABLED
!.   &FALSE
 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2  


INNERHTML
(4  9 $ * $  & . HTML
0. ;T4 ' ! =G $  %84 2  
INNERTEXT
(4  9 $ * $  . HTML
  0G Server  
 +$ 8 2 $  RUNAT

W   CSS  0. (,8      ! STYLE

& 2 !W   0. + $    @ VISIBLE

:8
ID 6  @ $ @  
 +$ 8  2 (,8 <P> % =G 1 ! *7 ! *
:innerHtml  @ ? Submit  (,8  K$ V ,
7  0  
<script runat="server">
Sub submit(sender As Object, e as EventArgs)
if name.value<>"" then
p1.InnerHtml="Welcome " & name.value & "!"
end if
End Sub
</script>

<html>
<body>

<form runat="server">
Enter your name: <input id="name" type="text" size="30" runat="server" />
<br /><br />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>

</body>
</html>

:HTMLIMAGE   


% =G  . %    
 +$ 8 A=4 (,8 0. +$ 8 *
:  0. *7 I0  ? 5; .2  .<img>

Universal Knowledge Solutions s.a.l 55


   $ ! *+ (4  %  %0$   $ ALIGN
  0G 2 + top ,middle ,bottom ,left ,right
% ,   9 ALT

  @  0. 5# 1 


 W@   ATTRIBUTES

. -  8 BORDER

  @ *_#Q R T 2 *^#  0. + $    @


DISABLED
!.   &FALSE
%  U#  HEIGHT

 0   $ 9^ R ID

  0G Server  


 +$ 8 2 $  RUNAT

.  X4   % , !   $ SRC

W   CSS  0. (,8      ! STYLE

& 2 !W   0. + $    @ VISIBLE

%   8 WIDTH

:8
<script runat="server">
Sub choose_image(Sender As Object, e As EventArgs)
image1.Src = select1.Value
End Sub
</script>

<html>
<body>

<form runat="server">
<select id="select1" runat="server">
<option value="smiley.gif">Smiley</option>
<option value="angry.gif">Angry</option>
<option value="stickman.gif">Stickman</option>
</select>
<input type="submit" runat="server" value="Display image"
OnServerClick="choose_image">

Universal Knowledge Solutions s.a.l 56


<img id="image1" src="smiley.gif" runat="server" width="32" height="32" />
</form>

</body>
</html>

 %$   $ image1 +$ 8 . X ! %  *  I
 *7 0. !
. <option> +$

:HTMLInput   


  @  0. 5# 1 
 W@   ATTRIBUTES

  @ *_#Q R T 2 *^#  0. + $    @


DISABLED
!.   &FALSE
 0   $ 9^ R ID

 &  NAME


ONSERVERCLI
, /0. (,8  8 /0 #   I0 1  CK
  0G Server  
 +$ 8 2 $  RUNAT

W   CSS  0. (,8      ! STYLE

  TYPE

  @ VALUE

& 2 !W   0. + $    @ VISIBLE

:8
<script runat="server">
Sub submit(sender As Object, e as EventArgs)
if name.value<>"" then
p1.InnerHtml="Welcome " & name.value & "!"
end if
End Sub
</script>

<html>
<body>

<form runat="server">
Enter your name: <input id="name" type="text" size="30" runat="server" />
<br /><br />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>

Universal Knowledge Solutions s.a.l 57


</body>
</html>

! *$, Value     ! submit  8 #  W


- *7 0. ! 
.<form>   html +$ 8 1 
A$ @ 2 X$; .name

:HTMLINPUTCHECKBOX   1.4.14


  @  0. 5# 1 
 W@   ATTRIBUTES

& 2 /    @  + $    @ CHECKED

  @ *_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &FALSE
 0   $ 9^ R ID

 &  NAME

  0G Server  


 +$ 8 2 $  RUNAT

W   CSS  0. (,8      ! STYLE

 U TYPE

  @ VALUE

& 2 !W   0. + $    @ VISIBLE

:*7
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
if red.Checked=True then
p1.InnerHtml="You prefer red!"
else
p1.InnerHtml="You prefer blue!"
end if
red.checked=false
blue.checked=false
End Sub
</script>

<html>
<body>
<form runat="server">
What color do you prefer?
<br />
<input id="red" type="checkbox" runat="server" /> Red
<br />
<input id="blue" type="checkbox" runat="server" /> Blue
<br />
<input type="button" value="Submit" OnServerClick="submit" runat="server"/>
<p id="p1" runat="server" />

Universal Knowledge Solutions s.a.l 58


</body>
</html>

HTMLINPUTHIDDEN   

  @  0. 5# 1 


 W@   ATTRIBUTES

  @ *_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &FALSE
 0   $ 9^ R ID


 4 NAME

  0G Server  


 +$ 8 2 $  RUNAT

!C"  # CSS # ?% 0 (


 4 5  STYLE

#  TYPE

#  = VALUE

 & 5C  # ?%      = VISIBLE

:*7

<script runat="server">
Sub submit(Source As Object, e As EventArgs)
hidden1.Value=string1.Value
p1.InnerHtml="Hidden value= " + hidden1.Value
End Sub
</script>

<html>
<body>

<form runat="server">
Enter some text: <input id="string1" type="text" size="25" runat="server" />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<input id="hidden1" type="hidden" runat="server" />
<p id="p1" runat="server" />
</form>

</body>
</html>

Universal Knowledge Solutions s.a.l 59


:HTMLINPUTIMAGE   
%  %0$ ALIGN

*   ALT

  @  0. 5# 1 


 W@   ATTRIBUTES

%   -  8 BORDER

  @ *_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &FALSE
 0   $ 9^ R ID

 &  NAME

, /0. (,8  8 /0 #   I0 1  ONSERVERCLI
CK
  0G Server  
 +$ 8 2 $  RUNAT

!   $ SRC

W   CSS  0. (,8      ! STYLE

 U TYPE

  @ VALUE

& 2 !W   0. + $    @ VISIBLE

:*7
<script runat="server">
Sub button1(Source As Object, e As ImageClickEventArgs)
p1.InnerHtml="You clicked the smiley button!"
End Sub
Sub button2(Source As Object, e As ImageClickEventArgs)
p1.InnerHtml="You clicked the angry button!"
End Sub
</script>

<html>
<body>

<form runat="server">
<p>Click on one of the images:</p>
<p>
<input type="image" src="smiley.gif"
OnServerClick="button1" runat="server" width="32" height="32" />
</p>
<p>

Universal Knowledge Solutions s.a.l 60


OnServerClick="button2" runat="server" width="32" height="32" />
</p>
<p id="p1" runat="server" />
</form>

</body>
</html>

72 EventArgs  8 <8 imageClickEventArgs   *7 0. ! X$;
.%  (,8  K$ V 9 

HTMLINPUTRADIOBUTTON   


  @  0. 5# 1 
 W@   ATTRIBUTES

 & U  "  = #      = CHECKED

  @ *_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &FALSE
 0   $ 9^ R ID


 4 NAME

  0G Server  


 +$ 8 2 $  RUNAT

!C"  # CSS # ?% 0 (


 4 5  STYLE

#  TYPE

#  = VALUE

 & 5C  # ?%      = VISIBLE

:*7
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
if r1.Checked=True then
p1.InnerHtml="Your favorite color is red"
else
if r2.Checked=True then
p1.InnerHtml="Your favorite color is green"
else
if r3.Checked=True then
p1.InnerHtml="Your favorite color is blue"
end if
end if
end if
End Sub
</script>

<html>

Universal Knowledge Solutions s.a.l 61


<form runat="server">
<p>Select your favorite color:
<br />
<input id="r1" name="col" type="radio" runat="server">Red</input>
<br />
<input id="r2" name="col" type="radio" runat="server">Green</input>
<br />
<input id="r3" name="col" type="radio" runat="server">Blue</input>
<br />
<input type="button" value="Submit" OnServerClick="submit" runat="server"/>
<p id="p1" runat="server" />
</form>

</body>
</html>

HTMLINPUTTEXT   

  @  0. 5# 1 


 W@   ATTRIBUTES

  @ *_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &FALSE
 0   $ 9^ R ID

&0‫د‬23 ‫ح‬56‫ ا‬7'8‫د ارف ا‬# MAXLENGHT


 &  NAME

  0G Server  


 +$ 8 2 $  RUNAT

;"‫!ض ا< ا‬# SIZE


W   2 $ CSS 0. (,8      ! STYLE


!">‫ع ا‬5‫ﻥ‬ TYPE
!">‫' ا‬ VALUE
& 2 !W   0. + $    @ VISIBLE

HTMLSELECT   

  @  0. 5# 1 


 W@   ATTRIBUTES

+$ 8 1   5  *


 DATAMEMBER

 5    DATASOURCE

 5   *$  /  X4 , *$ DATATEXTFIEL


D

Universal Knowledge Solutions s.a.l 62



 *$   ,     *$ DATAVALUEFIE
LD
5 
*_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &   @FALSE
 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2   INNERHTML

(4  9 $ * $  & . HTML


0. ;T4 ' ! =G $  %84 2   INNERTEXT

(4  9 $ * $  . HTML


 W   W@ ITEMS

# ! W  8  7+2    +4 $ MULTIPLE

5@
V !  8 #  W
-  (4   /0. 
ONSERVERCHA
NGE
W   , ? K$
  0G Server 
 +$ 8 2 $  RUNAT


/    I0  $ ' $ 8 . *  SELECTEDINDE
X
T  *$ ! 1  (4      & W@ U#  SIZE

. W@ A=[


W   CSS  0. (,8      ! STYLE

   @ VALUE

& 2 !W   0. + $    @ VISIBLE

:*7

<script runat="server">
Sub choose_image(Sender As Object, e As EventArgs)
image1.Src = select1.Value
End Sub
</script>

Universal Knowledge Solutions s.a.l 63


<body>

<form runat="server">
<select id="select1" runat="server">
<option value="smiley.gif">Smiley</option>
<option value="angry.gif">Angry</option>
<option value="stickman.gif">Stickman</option>
</select>
<input type="submit" runat="server" value="Display image"
OnServerClick="choose_image">
<br /><br />
<img id="image1" src="smiley.gif" runat="server" width="32" height="32" />
</form>

</body>
</html>

HTMLTABLE   

*
 %0$ $ ALIGN

  @  0. 5# 1 


 W@   ATTRIBUTES

 #,  $ BGCOLOR

*
, - + $ BORDER

*
, -  $ BORDERCOLOR

 , B$ -   $ CELLPADDING

. ;   $ CELLSPACING

*_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &   @FALSE
*
 U#  $ HEIGHT

 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2   INNERHTML

(4  9 $ * $  & . HTML


0. ;T4 ' ! =G $  %84 2   INNERTEXT

(4  9 $ * $  . HTML


! %
 9# 8 1 
I$ 8
   ROWS

*

  0G Server 
 +$ 8 2 $  RUNAT

Universal Knowledge Solutions s.a.l 64



W   CSS  0. (,8      ! STYLE

& 2 !W   0. + $    @ VISIBLE

*
  8  WIDTH

:*7

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
dim i,j
table1.BGColor="yellow"
table1.BorderColor="red"
for i=0 To table1.Rows.Count-1
for j=0 To table1.Rows(i).Cells.Count-1
table1.Rows(i).Cells(j).InnerHtml="Row " & i
next
next
End Sub
</script>

<html>
<body>

<form runat="server">
<table id="table1" border="1" runat="server">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
<br />
<input type="button" value="Change Contents" OnServerClick="submit" runat="server"/>
</form>

</body>
</html>

HTMLTABLECELL   

AB‫ ا‬$C D"A ‫اذاة‬ ALIGN


  @  0. 5# 1 
 W@   ATTRIBUTES

AB‫ن ا‬5 BGCOLOR

Universal Knowledge Solutions s.a.l 65


‫)ر‬G‫ن ا‬5 BORDERCOLOR
AB‫ ا‬HA# !*6 ‫ أن‬JK‫ة ا*; ی‬#8‫د ا‬# COLSPAN
*_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &   @FALSE
AB‫ارع ا‬ HEIGHT
 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2   INNERHTML

(4  9 $ * $  & . HTML


0. ;T4 ' ! =G $  %84 2   INNERTEXT

(4  9 $ * $  . HTML


AB‫ ا‬HA# !*6 ‫ أن‬JK‫ف ا*; ی‬5‫د ا‬# ROWSPAN
  0G Server 
 +$ 8 2 $  RUNAT


W   CSS  0. (,8      ! STYLE

AB‫; ا‬L !‫>"ﺹ‬A 5'N‫اذاة ا‬ VALIGN


& 2 !W   0. + $    @ VISIBLE

AB‫!ض ا‬# WIDTH

:*7

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
Dim row,numrows,numcells,j,i
row=0
numrows=rows1.Value
numcells=cells1.Value
for j=1 to numrows
Dim r As New HtmlTableRow()
row=row+1
for i=1 to numcells
Dim c As New HtmlTableCell()
c.Controls.Add(New LiteralControl("row " & j & ", cell " & i))
r.Cells.Add(c)
next
t1.Rows.Add(r)
t1.Visible=true
next
End Sub
</script>

<html>
<body>

Universal Knowledge Solutions s.a.l 66


<form runat="server">
<p>Table rows:
<select id="rows1" runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<br />Table cells:
<select id="cells1" runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<br /><br />
<input type="submit" value="Display Table" runat="server" OnServerClick="submit">
</p>
<table id="t1" border="1" runat="server" visible="false"/>
</form>

</body>
</html>

HTMLTABLEROW   

!O6‫ ا‬$C !‫ﻡذاة ا>"ﺹ‬ ALIGN


  @  0. 5# 1 
 W@   ATTRIBUTES

AB‫ن ا‬5 BGCOLOR


‫)ر‬G‫ن ا‬5 BORDERCOLOR
!O6‫ا ا‬.‫ ه‬$C ‫دة‬5‫ﺝ‬5‫(ی ا‬B‫ی> ا‬ CELLS
*_#Q R T 2 *^#  0. + $    @ DISABLED

!.   &   @FALSE
!O6‫ارع ا‬ HEIGHT
 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2   INNERHTML

(4  9 $ * $  & . HTML


0. ;T4 ' ! =G $  %84 2   INNERTEXT

(4  9 $ * $  . HTML


  0G Server 
 +$ 8 2 $  RUNAT


W   CSS  0. (,8      ! STYLE

!O6‫ ا‬$C ً5'‫ﻡذاة ا>"ﺹ! ﺵ‬ VALIGN

Universal Knowledge Solutions s.a.l 67


& 2 !W   0. + $    @ VISIBLE

HTMLTEXTAREA   

  @  0. 5# 1 


 W@   ATTRIBUTES

D"‫ ا‬S3!‫!ض ﻡ‬# COLS

*_#Q R T 2 *^#  0. + $    @


DISABLED
!.   &   @FALSE

 0   $ 9^ R ID

0. ;T4 ' ! =G $  %84 2  


INNERHTML
(4  9 $ * $  & . HTML
0. ;T4 ' ! =G $  %84 2  
INNERTEXT
(4  9 $ * $  . HTML

D"‫ ا‬S3!‫اﺱ ﻡ‬ NAME

7A# !U*‫ ﺡث ا‬K> ‫ه‬." *‫ ا*; ﺱ‬V‫ﺝ!ا‬G‫اﺱ ا‬ ONSERVERCHA


D"‫ ا‬S3!‫ى ﻡ‬5*‫ﻡ‬ NGE

D"‫ ا‬S3!‫ارع ﻡ‬ ROWS

  0G Server 


 +$ 8 2 $ 
RUNAT


W   CSS  0. (,8      ! STYLE

D"‫ ا‬S3!‫ى ﻡ‬5*‫ﻡ‬ VALUE

& 2 !W   0. + $    @ VISIBLE

Universal Knowledge Solutions s.a.l 68


:*7

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
p1.InnerHtml = "<b>You wrote:</b> " & textarea1.Value
End Sub
</script>

<html>
<body>

<form runat="server">
Enter some text:<br />
<textarea id="textarea1" cols="35" rows="6" runat="server" />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>

</body>
</html>

P" 

: 
 
  P0 +$ 8

:   
K$2    W % =G     
 +$ 8

:!"
3, .2 !.  
 +$ 8  .  $# 5+ +2 +$ $ %  5  ASP.NET 5@
.5 
.  P0 +$ 8   ,8 ,  
 +$ 8  B 2 8
 ,
 /0. !  

Universal Knowledge Solutions s.a.l 69


:  # $%&
:(,8 *# 0. !  9 
 
 +$ 8 •
 
 +$ 8 W •

 +$ 8 +$ 8 *$ 8 ,72 * # •



+$ 8   ,8 ,2  


 +$ 8  8
   ,
 !  
.HTML

*8# +  (,8 $#  S


QR 8 !.  
 +$ 8 2  2
!
   +  + W    K$& % 
     (4 *& '  
.C *, 4 *  <$ 7+2

!   HTML 5 =G  


 5W+ &4 +  HTML +$ 8
^ 2 < 2 X$&
.  ,8# 5$# P0 A=-   H *+= * 

+$ 8   ,8 ,  


 +$ 8  B 2 8
 ,
 /0. !  
.  P0

 >?  

>?   HTML C2



<ASP:HyperLin <a>...</a>
k>
<ASP:LinkButt <a><img/></a>
on>
<ASP:Image> <img/>
<ASP:Panel> <div>...</div>
Universal Knowledge Solutions s.a.l 70
<ASP:Label> <span>...</span>
<ASP:Button> <input type="submit"/> or <input type="button"/>
<ASP:TextBox <input type="text"/> 2 <input type="password"/> 2
>
<textarea>...</textarea>
<ASP:CheckBo <input type="checkbox"/>
x>
<ASP:RadioBut <input type="radio"/>
ton>
<ASP:ImageBut <input type="image"/>
ton>
<ASP:Table> <table>...</table>
<ASP:TableRo <tr>...</tr>
w>
<ASP:TableCell <td>...</td>
>

C  I0 *, C= *   P0 +$ 8  B 2 8
 
 < T  @ o
:(4 30 !   .HTML +$ 8
. 5
 < W,  ! 5  5> A  ,8 *  -
I0 > HTML +$ 8 *8      @ *@G  P0 A=4  ,8 *  -
.A2 
  8 *@2 
   *

#   !  W %$ A2  P0 +$ 8  HTML +$ 8 + o
> 8 listBox 8 HTML +$  SIZE  *7 *7 *  (, .&
+ H HTML +$ 8 ! Cols  /0.  '   .W   W 
1 
! %$ +$ 8  8 8  ! WIDTH  + $ ! .TextArea
.  8  $ P$ !  P0 +$ 8

*+= W >  ; HTML P  .   9  > 


$ 3.   o
.  P0    W  @  (,8 C   04  ,

2 $ 1    ,  W, 4 *7 %8  4 5   P0 8  3, o
.    

Universal Knowledge Solutions s.a.l 71


 P0 +$ 8 K$2 W  W

+ =6 36, 6  +06 .K$> W  W     P0 +$ 8 
:Webcontrols 9  7 

W 9
 
K$>
 .(  @ ) 5 W7 1 
%84
Attributes & ! W)    T W %A    +
?, I   9   <A
*+=HTML (4 *, 2 (
.+S =R T    W
 .    (,8 8 I0 & \# %84
AccessKey
 . #,   $
BackColor
 . -  %84
BorderColor
 .(....   )  4  %84
BorderStyle
 . - + %84
BorderWidth
 *@     9   @ %84 ASP.NET
ClientID
 ( >) !$ +$   (A>) +$ 8 %84.
Controls
 .& 2 ;
< #  + 04  %84
Enabled
  @ (,8 X$   + 04   $    @ %84
EnableViewS ?Viewstate .CW2 1 
  0 
tate
  U %84
Font
Universal Knowledge Solutions s.a.l 72
 +$ 8  2 B$  , %84
ForeColor
 .  U#  %84
Height
 0. +$   9  %84
ID
 +$ 8 (,8 I$ $# W+ (4 =J %84
Page
 8 @; !  *,  +$ 8 2 (4 =J  
Parent .$# W+  +$
 > 1 
8
 *7 CSS+$ 8 (,8 
Style
 ? B  & *    +$ 8 *, %84
TabIndex  Tab
 .+$ 8  % G# =J 3 $ B X I0  %84
ToolTip
 P  ! +$ 8  X4 2 A#4 $    @ %84
Visible .$#
  .CW2 1 
! +$ 8 ! 5     * #
DataBind
 .+$ 8  8 %84
Width
   +$ 8 8 !$ W+  K$
FindControl
  +$ 8 +$  + 04   $    @ %84
HasControls .A
K$ 5   +$ 8  8 K$ 0. X
DataBinding

 P0 +$ 8 K$2    W

Universal Knowledge Solutions s.a.l 73


 P0 +$ 8 K$2 W  W

6.2    !,   . 7  ! 3, (4 < 4 %   W  W   +$ 8 3,
.+$ 8 $ W W  3,

HyperLin
ImageUrl, NavigateUrl, Target, Text -
k
OnClick,
LinkButto CommandArgument, CommandName,
OnComm
n Text, CausesValidation
and
Image AlternateText, ImageAlign, ImageUrl -
Panel BackImageUrl, HorizontalAlign, Wrap -
Label Text
OnClick,
CommandArgument, CommandName,
Button OnComm
Text, CausesValidation
and
AutoPostBack, Columns, MaxLength,
OnTextC
TextBox ReadOnly, Rows, Text, TextMode,
hanged
Wrap
CheckBo OnCheck
AutoPostBack, Checked, Text, TextAlign
x Changed
OnCheck
RadioButt AutoPostBack, Checked, GroupName,
Changed
on Text, TextAlign
OnClick,
OnComm
ImageBut CommandArgument, CommandName,
and
ton CausesValidation

BackImageUrl, CellPadding, CellSpacing,


GridLines,
Table -
HorizontalAlign, Rows

TableRo
Cells, HorizontalAlign, VerticalAlign -
w
ColumnSpan, HorizontalAlign, RowSpan,
TableCell -
Text, VerticalAlign, Wrap
Literal Text -
PlaceHol
- -
der

Universal Knowledge Solutions s.a.l 74


6 F *6
 ! 
 . 7  ! 3, (4 < 4 %   W  W   +$ 8 3,
.+$ 8 $ W W  3, .2   

 >?  


:1 8
16 *   HTML +$ 8 1 *    ' C= ! *7 ! X$;
68 V6 K6$ V + @ button1 9   A=[ @    P0 +$ 8
:*7   ! *# *+= C?
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
button1.Text="You clicked me!"
End Sub
</script>

<html>
<body>

<form runat="server">
<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit"/>
</form>

</body>
</html>

:2 8
6 & 6 %   $ @ 2 X$; K $ !=  & +$ 8 !7 7 *
!6 %06 6 - 9  I0 (URL) !  I  $  @  (4 -
.   & ' I


<html>
<body>

<form runat="server">
<asp:HyperLink ImageUrl="myImage.jpg" NavigateUrl="http://www.sk-www.com"
Text="Visit sk!" Target="_blank" runat="server" />
</form>
</body>
</html>
.

+$ 8 1 *    P0 +$ 8 1 *    ' C= 3.
.  /0.  ?   H   ,7> ' .HTML

Universal Knowledge Solutions s.a.l 75


 >?   !C"
!C"  = 52 $. "

6+ 9 $ *; (,8  W  @ > < X   HTML +$ 8   
.  HTML 5 =G ! *$ .

@ R  @ 8 2  T2 8 % 8   /0. + 2 + 04  P0 +$ 8 1 *$ 9,
 P06 +$  (  
 (4 %  %0$ 8 + *7 *  (, .(Enumerated)
:%  
<ASP:Image Src="mypic.gif" ImageAlign="Right" runat="server" />
6   6    8  9  K $ imageAlign.Right ,  @ A84 I

.C
I0

!6 I06 #    0. 4


 !
   0 # A72    T 04 2
:$#
objMyImage.ImageAlign = ImageAlign.Right
: 4 2
objMyImage.ImageAlign = 2

 6, import   30 @ R  A2   (,8 TypeDescriptor  ? 8
.  Namespace 6 1
<%@Import Namespace="System.ComponentModel" %>
TypeDescriptor.GetConverter(GetType(HorizontalAlign)).ConvertFromSt
ring("Left")

: * = * $  1  2


Dim intValue = CType(HorizontalAlign.Left, Integer)

6+ 9 $ *; (,8  W  @ > < X   HTML +$ 8   
.  HTML 5 =G ! *$ .

@ R  @ 8 2  T2 8 % 8   /0. + 2 + 04  P0 +$ 8 1 *$ 9,
Universal Knowledge Solutions s.a.l 76
.(Enumerated)

 >?   !C"

 @ 6 !6 
Q6R    $ .NET *8 4  WinCV %>   < 2 +
:*+= ! X + 

*$, ,  (,8  > A


 ! ? 7  8 &  A
 K$ !#+ K $
.  $   (,8

. T (4 = !  G= 0 + @ R ,  0.

BackColor, W6 6$2 (4   4 $ !.   (> ,.,  @ $ 0G
6,  @ A84  7+2 (4 ,  @    m+ 04 P$ & @ .ForeColor, BorderColor)
:%< =
<asp:textbox id="MyText" Text="This is a textbox" runat="server"
BackColor="Red" ForeColor="White" />

. ,  (4 /4 7    T 9  + +


 @  ! 
QR    $ .NET *8 4  WinCV %>   < 2 +

 >?  !C"
System.Drwaing.Color $

Universal Knowledge Solutions s.a.l 77


( White Antique AliceBlue *67)  6  HTML 2 1 
 W Color 9 9 
: ,   T A=- W   8
  (4 4

FromArgb 6$> (4 < 4  #= :C+  *;   A=[ 
. > >
FromKnownCol ! % 5 , < ,    W+ A=[ 
or
HTML
FromName   # ,  =8      W+ A=[ 
! HTML

:8

<%@Import Namespace="System.Drawing" %>


MyControl.BackColor = Color.FromName(“ff0000”)

( White Antique AliceBlue *7)    HTML 2 1 


 W Color 9 9 
: ,   T A=- W   8
  (4 4

 >?   !C"


P  
!" Unit $

W *$+   P0 +$ 8 W    (4 Unit 9   T2 4 I

Width Border Height Width
:   %$ (,8 &, Px  %  @ *7 0. ! X$; +
<asp:image id="MyImage" Src="mypic.gif" runat="server"
Height="100px" Width="50%" />

*68 A672  6@ A8- 9 . ! W W   +   /0. (4 4
.V 

C6> / & !8 & 30  P0 +$   A> A  A
Unit 9 +

Universal Knowledge Solutions s.a.l 78


.<   + 

:    W Unit 9 '

 Type 0G 2 +  %$ U $


 66666666 B66666666$4
Cm,Mm,Em,Ex,Inch,Percentage,
Pica,Pixel,Point
 Value 5$ 8
 Percentage W6+ A=6[ Unit 6 6
Percentage
 Pixel W+ A=[ Unit   Pixel
 Point W+ A=[ Unit   Point

:*7
MyControl.Height=Unit.Pixel(50)

.*+ %   U#   @ 50  *7 *7 !

W *$+   P0 +$ 8 W    (4 Unit 9   T2 4 I

.Width Border Height Width

 >?   !C"


AutoPostBack "

6 68   B P0 * 4  ,8 * # 5&$    ! , !,8# P0 A 8
. 5   
& 8 $# K $ , ' R K $    1  * # 2 W@

6$ *  2   K$    


 K$  (ASP !) <   , /0. 5+
: ! + OnChange K$+
Universal Knowledge Solutions s.a.l 79
<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform = document.ctrl0;
theform.__EVENTTARGET.value = eventTarget;
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
<input id="MyControl" type="checkbox" name="MyControl"
onclick="javascript:__doPostBack('MyControl','')" />
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
// -->

$#6 * 4 I
($ AutoPostBack  (4 True   4 !#+  ASP.NET ! 2
.C  /0.   I0 +$ 8 (,8 *  *+   (4

:AutoPostBack "

6 8  & B P0, * 4  ,8 * # 5&$    ! , !,8# P0 A 8
. 5   
& B $# K $ , '    1  * # 2 ;
< 7 W@
(64 $# * 4   True   (4 AutoPostBack    @  !#+ ASP.NET !
.True (4 C   /0.  @   I0 +$ 8 (,8 *  *+  

 >?   !C"


ASP.NET  EnableViewState "

6$2 A* ! G 


 / 8 A#  <
 P0 B$ A* %84 (4  %< 8 
6 !# P0 8  @ 5+ 04 ASP  (,8 *,   # /0. 5+ @ .5,
.$ /0. 
 !
   +  V ,  & + C 4

/A6?4 V 6 6$    W, %  *_ #Q R P0 B$ (,8 A- +  ASP.NET ! 2
:%  $#   @ % 
<%@ Page EnableViewState="false" %>

Universal Knowledge Solutions s.a.l 80


6 $   $>  /0. 9 4 + 2 ASP.Net $#   ! %  /0. 1

*6$ 8 ,+ 8 ;
< 7 $ /0.  2 + .  0  EnableViewState="false"
.  ,+ *- 

: *7

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Hello " & txt1.Text & "!"
End Sub
</script>

<html>
<body>

<form runat="server">
Your name: <asp:TextBox id="txt1" runat="server"
EnableViewState="false" />

<asp:Button OnClick="submit" Text="Submit" runat="server" />


<p><asp:Label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

6$2 A* ! G 


 / 8 A#  <
 P0 B$ A* %84 (4  %< 8 
6 !# P0 8  @ 5+ 04 ASP  (,8 *,   # /0. 5+ @ .5,
.$ /0. 
 !
   +  V ,  & + C 4

/A?4 V  $    W, %  *_ #Q R P0 B$ (,8 A- +  ASP.NET ! 2
.$#   @ % 

8

 * # X$; K $ checkBoxList  P0 +$ 8  ! *7 !
  [ W 8  8 I2 (,8 %  *+ 8 V  0.   .AutopostBack

Universal Knowledge Solutions s.a.l 81


mess @,    @ (,8 ;
< ^ #R + 04
<script runat="server">
Sub Check(sender As Object, e As EventArgs)
dim i
mess.Text="<p>Selected Item(s):</p>"
for i=0 to check1.Items.Count-1
if check1.Items(i).Selected then
mess.Text+=check1.Items(i).Text + "<br />"
end if
next
End Sub
</script>

<html>
<body>
<form runat="server">
<asp:CheckBoxList id="check1" AutoPostBack="True"
TextAlign="Right" OnSelectedIndexChanged="Check"
runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:label id="mess" runat="server"/>
</form>
</body>
</html>
*+= (,8 + *7 0. 0 # 


8
. DropDownList  P0 +$ 8  ! *7 !
.   (,8 I$   X[ Submit  (,8  8 V  0.  

Universal Knowledge Solutions s.a.l 82


<script runat="server">
Sub submit(sender As Object, e As EventArgs)
mess.Text="You selected " & drop1.SelectedItem.Text
End Sub
</script>

<html>
<body>

<form runat="server">
<asp:DropDownList id="drop1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:DropDownList>
<asp:Button Text="Submit" OnClick="submit" runat="server"/>
<p><asp:label id="mess" runat="server"/></p>
</form>

</body>
</html>

:*+= (,8 *7 0. 0 # 


 +

8
. DropDownList  P0 +$ 8 ! *7 ! 
.   (,8 I$   X[ Submit  (,8  8 V  0.  

<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
if check1.Checked then
panel1.Visible=false
else
panel1.Visible=true
end if
End Sub
</script>

Universal Knowledge Solutions s.a.l 83


<html>
<body>

<form runat="server">
<asp:Panel id="panel1"
runat="server" BackColor="#ff0000"
Height="100px" Width="100px">
ASP.NET
</asp:Panel>
<asp:CheckBox id="check1"
Text="Hide Panel control"
runat="server"/>
<br /><br />
<asp:Button Text="Reload" runat="server" />
</form>

</body>
</html>

:*+= (,8 *7 0. 0 # 


 +

8
: tableCell,tableRow table  P0 +$ 8 ! *7 ! 

<html>
<body>

<form runat=server>
<asp:Table runat="server" CellPadding="5"
GridLines="horizontal" HorizontalAlign="Center">
<asp:TableRow>

Universal Knowledge Solutions s.a.l 84


<asp:TableCell>2</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>3</asp:TableCell>
<asp:TableCell>4</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br />
<asp:Table runat="server" CellPadding="5"
GridLines="vertical" HorizontalAlign="Center">
<asp:TableRow>
<asp:TableCell>1</asp:TableCell>
<asp:TableCell>2</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>3</asp:TableCell>
<asp:TableCell>4</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>

</body>
</html>
:*+= (,8 *7 0. 0 # 
 +

8
TextBox U  P0 +$  #, W *7 0. '
<html>
<body>
<form runat="server">
A basic TextBox:
<asp:TextBox id="tb1" runat="server" />
<br /><br />
A password TextBox:
<asp:TextBox id="tb2" TextMode="password" runat="server" />
<br /><br />
A TextBox with text:
<asp:TextBox id="tb3" Text="Hello World!" runat="server" />
<br /><br />

Universal Knowledge Solutions s.a.l 85


<asp:TextBox id="tb4" TextMode="multiline" runat="server" />
<br /><br />
A TextBox with height:
<asp:TextBox id="tb5" rows="5" TextMode="multiline" runat="server"
/>
<br /><br />
A TextBox with width:
<asp:TextBox id="tb6" columns="30" runat="server" />
</form>
</body>
</html>

:*+= (,8 *7 0. 0 # 


 +

P4 

: 
.*-  $ +$ 8

:   
K$2 W   W % =G     
 +$ 8

Universal Knowledge Solutions s.a.l 86


:!"
.  (,8   I2 ! !2 A
*-  $  ,8 *+=
$  $ +$ 8   ,8 ,  
 +$ 8  B 2 8
 ,
 /0. !  
*-

:  # $%&
:(,8 *# 0. !  9 
 
 *4  $ +$ 8 •
 3, 8 *$ 8 ,72 * # •

*  8 8 J +$ 8

Input Validation Control

+ 04 . ,8#  P0 A ! <    7+2  *  8  $ 5, 5+ 
U2 %8 1    ? <T +   B (,8 2  B (,8  2  , /0 
 
 JavaScript ?  *$ 2  9    , /0   5$# 
.#, 5$# U2 1   7+2  +

,$ 5.   ,T2 !? Input Validation +$ 8  8
 ASP.NET 
Input +$ 8 A=-   + , ,@ +$ 8   (4 < 4 $ 5 ,
.  @ T Validation

:  *+ 9  1 Input Validation +$  W@ !,  

+$ 8 9


+G  I0  2  $ 
<asp:requiredFieldValidator>
. @ (, $ C

Universal Knowledge Solutions s.a.l 87


1   0.  +
8Input Validation B 2
.T #  

I0  !   2  +G 
$ *
  1 C +G 
<asp:RangeValidator>
 8
 *= *
 0. + A
.@ > 2 9 $
+G  !   2  $ 
8    +$   
<asp:CompareValidator>
. %$   2 H +$
C   I0 +$ 8 + 04
.+G  ,8  & !
 I0 +$ 8 2  +G 
<asp:RegularExpressionValidator .!X   C +G
>
C   I0 +$ 8 + 04
.+G  ,8  & !
5 ,8 A=[ 0. +$ 8 '
1 8  *@   _ R +G
<asp:CustomValidator> 2  2  9    $
..;+
C   I0 +$ 8 + 04
.+G  ,8  & !
<asp:ValidationSummary> +G  ,8 AG   X[ 
. 


*  8 8 J +$ 8

Input Validation Control

+ 04 . ,8#  P0 A ! <    7+2  *  8  $ 5, 5+ 

Universal Knowledge Solutions s.a.l 88


U2 %8 1    ? <T +   B (,8 2  B (,8  2  , /0 
 
 JavaScript ?  *$ 2  9    , /0   5$# 
.#, 5$# U2 1   7+2  +

,$ 5.   ,T2 !? Input Validation +$ 8  8
 ASP.NET 
Input +$ 8 A=-   + , ,@ +$ 8   (4 < 4 $ 5 ,
.  @ T Validation

  V# & < 4 1? 


Input Validation

:  +G  ! *- +$ 8 $2 1  7+2 2 Input Validation +$ 8  I

   +G Input Validation +$ 8 *+   *@  $# * 4 8 •
.$  
  + 04   B  C   +$ 8 ! %

G   X[ ValidationSummary +$ 8  $  ! *= I2 *$ ! •
. & 
 $ %$
 !
      '# U 9=+ Input Validation +$ 8  •
.$  ,8 - $# !  

$# (,8 +$ 8 B$  X- DHTML ?  


 !
    •
.!+   *+=

    C, +  + *+=  =  8 
 50 
 *$ 0.  •
. <  % 

$  , .1@ 5$# A! &   $ <  2 Controls Input +$ 8 J
 %A ! T 0 =d + 04 H T  + %
 9   * 
5;  $  & K $  , ! 5$# (,8 *  2   $# A=4 1@
.$ T 5, * [ 3  . ,$  30  + 

&4   9   *  $  Validation +$ 8 +  T  *$ I2 (,8
$ ! 
 8  (,8 *$ 1  0  $# * 4 8  (,8 $# #   2

Universal Knowledge Solutions s.a.l 89


. 
 
   $ ! > (,8   
 

 +4 (4 4  4 


$ 8 *$ !  
 *  $;  $  ,8 A?4 +
8  8 <8  G    ,# %  * 5   $;  $
.ValidationSummary +$

BaseValidator 9

I8 9 K$2 W  W Validation +$ 8 1 


K  •
.BaseValidator

A> A  <A


BaseValidator 9 R •
System.Web.UI.WebControls

+$ 8 1 
1 + = W  W  8
 BaseValidator 9  •
.Validation

:W  W 3, .2 •


+$ 8 W K$>
RequiredFieldValid
InitialValue
ator -

RangeValidator MaximumValue, OnServerValid


MinimumValue, Type ate
DisplayMode,
ShowHeaderText,
validationSummary -
ShowMessageBox,
ShowSummary

I8 9 K$2 W  W Validation +$ 8 1 


K  •
Universal Knowledge Solutions s.a.l 90
.BaseValidator

A> A  <A


BaseValidator 9 R •
System.Web.UI.WebControls

+$ 8 1 
1 + = W  W  8
 BaseValidator 9  •
.Validation

RequieredFieldValidator     

.$  '


  ,   @ *4  0. ,

: *7
A Required Value:
<input type="text" id="txtRequired" size="20" runat="server" />
<asp:RequiredFieldValidator id="valRequired" runat="server"
ControlToValidate="txtRequired"
ErrorMessage="* You must enter a value in the first textbox"
Display="dynamic">
*
</asp:RequiredFieldValidator>

+$ 8  C $   txtRequiered +$ 8  $ @ G X$;
.ControlToValidate  (4 txtRequiered   [ 30 RequieredFieldValidator

.ErrorMessage  *;   (4  84  ! G  $ < 2 @

./  X4    ($ $# ! + *$  +$ 8 + 04   Display  $

.$  '


  ,   @ *4  0. ,

Universal Knowledge Solutions s.a.l 91


CompareValidator   

.7  @ 2 H +$ 8  @ 1 ,  @   0. +$ 8 

   @  


! *4 *$ #2 2 X$; K $  *7,   ! *7 
 (4 txtRequired   ControlToValidate  (4 txtCompare
  $  ! +$ 8 A  . $ K $ ControlToCompare
. ;

:  B$4 0G 2 +    +$ I 8 ! @    U Operator  $
( Equal,greaterThan,LessThanOrEqual,..)

The Same Value Again:


<input type="text" id="txtCompare" size="20" runat="server" />
<asp:CompareValidator id="valCompare" runat="server"
ControlToValidate="txtCompare"
ControlToCompare="txtRequired"
Operator="Equal"
ErrorMessage="* You must enter same value in the second textbox"
Display="dynamic">
*
</asp:CompareValidator>

! + 7  @ 1 +$ 8 *   CompareValidator +$ 8  + +
:! *7

A Date after 27rd July 2005:


<input type="text" id="txtCompareDate" size="10" runat="server" />
<asp:CompareValidator id="valCompareDate" runat="server"
ControlToValidate="txtCompareDate"
ValueToCompare="27/6/2005"
Operator="GreaterThan"
Type="Date"
ErrorMessage="* The Date must be later than 27rd July 2005"
Display="dynamic">
*

Universal Knowledge Solutions s.a.l 92


</asp:CompareValidator>

 ! ,     CompareValidator +$ 8  2 . X$;
!W,  (,8 <8  
  2 X$; ."27/6/2005" 7   1 txtCompareDate
.Type=”Date”   f  C2 (,8 5   $ * String .

.Currency,Double,Date,Integer,String !. 5 , $ > +

:CompareValidator   


.7  @ 2 H +$ 8  @ 1 ,  @   0. +$ 8 

   @  


! *4 *$ #2 2 X$; K $  *7,   ! *7 
 (4 txtRequired   ControlToValidate  (4 txtCompare
  $  ! +$ 8 A  . $ K $ ControlToCompare
. ;

:  B$4 0G 2 +    +$ I 8 ! @    U Operator  $
( Equal,greaterThan,LessThanOrEqual,..)

.7  @ 1 +$ 8 *   CompareValidator +$ 8  + +

Range Validator  

. +$ 8 .0G 2 + !  , \ *


  $ 0. +$ 8 

 5   (> , : 2 W K;7  $  0. $ 8 $ !  &
.$    4 \    ,   $ 77  7 2

 MaximumValue   7   Type  (>  
.MinimumValue 77 

Universal Knowledge Solutions s.a.l 93


10  1    Type , Integer   [  2 X$; ! !
   !#
MinimumValue MaximumValue ,

A Number between 1 and 10:


<input type="text" id="txtRange" size="5" runat="server" />
<asp:RangeValidator id="valRange" runat="server"
ControlToValidate="txtRange"
MaximumValue="10"
MinimumValue="1"
Type="Integer"
ErrorMessage="* The Number must between 1 and 10"
Display="dynamic">
*
</asp:RangeValidator>

. +$ 8 .0G 2 + !  , \ *


  $ 0. +$ 8 

 5   (> , : 2 W K;7  $  0. $ 8 $ !  &
.$    4 \    ,   $ 77  7 2

 MaximumValue   7   Type  (>  
.MinimumValue 77 

-
#  " 4
:   

    $  ! 5 =-    8


 8 % 8  G  X  9_ F
:  /0. =2  .5 ,
| ? \ [] * + ^ .

  @   +G   X   Validation +$ 8 ASP.NET 3,
.ValidationExpression   !X  ?   $  .$ !X  1 ,

8  *  2  +G,  X   +$ 8 ! *7 ! 
Universal Knowledge Solutions s.a.l 94
.' $ ! +4   8  . txtRegExpr  +$
.   K $ ValidationExpression , .*@.*\..* !X   2 X$;
9 $ I>  + 8 *  9 $ I2 8

Match Expression "<b>.*@.*\..*</b>":


<input type="text" id="txtRegExpr" size="40" runat="server" />
<asp:RegularExpressionValidator id="valRegExpr" runat="server"
ControlToValidate="txtRegExpr"
ValidationExpression=".*@.*\..*"
ErrorMessage="* Your entry does not match the regular expression"
Display="dynamic">
*
</asp:RegularExpressionValidator>

    $  ! 5 =-    8


 8 % 8  G  X  9_ F
.5 ,

  @   +G   X   Validation +$ 8 ASP.NET 3,
.ValidationExpression   !X  ?   $  .$ !X  1 ,

!" :   

! +$ 8  8 I2  , 2  82 .A


4  ! $  ,8 + 8
.CustomValidator  $ +$ 8  1   < . 

8 100  +2  @ *4  +G, Comparevalidator +$ 8 ! *7 ! 
:     $# CustomValidator +$

A Prime Number over 100:


<input type="text" id="txtCustom" size="5" runat="server" />
<asp:CompareValidator id="valComparePrime" runat="server"
ControlToValidate="txtCustom"
ValueToCompare="100"
Operator="GreaterThan"
Universal Knowledge Solutions s.a.l 95
Type="Integer"
ErrorMessage="* The Prime Number must be greater than 100"
Display="dynamic">
*
</asp:CompareValidator>
<asp:CustomValidator id="valCustom" runat="server"
ControlToValidate="txtCustom"
ClientValidationFunction="ClientValidate"
OnServerValidate="ServerValidate"
ErrorMessage="* Your knowledge of prime numbers is not optimal"
Display="dynamic">
*
</asp:CustomValidator>

OnserverValidate  ClientValidationFunction ! CustomValidator +$ 8 


.   $,  W=[  !  1 A  $

! +$ 8  8 I2  , 2  82 .A


4  ! $  ,8 + 8
.CustomValidator  $ +$ 8  1   < . 

OnserverValidate  ClientValidationFunction ! CustomValidator +$ 8 


.   $,  W=[  !  1 A  $

:!"   #


!" <
 

.  
  
  1   +$ 8 '
U2 1   (,82   
 1, !
   + !0 JavaScript %< 8 
.$#  !
   0. P 4 %   30 5$#

ControlToValidate="txtCustom"
ValueToCompare="100"
Operator="GreaterThan"
Type="Integer"
ErrorMessage="* The Prime Number must be greater than 100"
Display="dynamic">
*
</asp:CompareValidator>
<asp:CustomValidator id="valCustom" runat="server"
ControlToValidate="txtCustom"
ClientValidationFunction="ClientValidate"
OnServerValidate="ServerValidate"
ErrorMessage="* Your knowledge of prime numbers is not optimal"
Display="dynamic">
Universal Knowledge Solutions s.a.l 96
*
</asp:CustomValidator>
<script language="JavaScript">
<!--
// client-side validation function for CustomValidator
function ClientValidate(objSource, objArgs) {
var blnValid = true;
var intNumber = objArgs.Value;
if (intNumber % 2 == 1) {
var intDivisor = Math.floor(intNumber / 3);
if (intDivisor > 2) {
for (var i = 3; i <= intDivisor; i = i + 2) {
if (intNumber % intDivisor == 0) {
blnValid = false;
break;
}
}
}
else
blnValid = false;
}
else
blnValid = false;
objArgs.IsValid = blnValid;
return;
}
//-->
</script>

[  T (4 - ObjSource .  # (4 1


 $ +$ 8  9 + X$;
.1 0. 8  ObjArgs

IsValid *$ (4  @  ObjArgs 6 Value *$ *;  +$ 8  @ (,8 *$
.& 2 $ '
 04    $ ObjArgs 6 

A=- VB.NET   ,8


. 2 #    9   $    2
. 
 1

 ? +$ 8 (4 =J ;  (,8 1  $ /0. !
:Value ,  + +$ 8  @ (,8 I$ ServerValidateEventArgs

blnValid = false;

Universal Knowledge Solutions s.a.l 97


}
else
blnValid = false;
objArgs.IsValid = blnValid;
return;
}
//-->
</script>
Sub ServerValidate(objSource As Object, objArgs As
ServerValidateEventArgs)
Dim blnValid As Boolean = True
Try
Dim intNumber As Integer = objArgs.Value
'check that it's an odd number
If intNumber Mod 2 = 1 Then
'get the largest possible divisor
Dim intDivisor As Integer = intNumber \ 3
If intDivisor > 2 Then
Dim intLoop As Integer
'check using each divisor in turn
For intLoop = 3 To intDivisor Step 2
If intNumber Mod intDivisor = 0 Then
blnValid = False
Exit For
End If
Next
Else
blnValid = False
End If
Else
blnValid = False
End If
Catch objError As Exception
blnValid =False
Finally
objArgs.IsValid = blnValid
End Try
End Sub

.  
  
  1   +$ 8 '
U2 1   (,82   
 1, !
   + !0 JavaScript %< 8 
.$#  !
   0. P 4 %   30 5$#

:ValidationSummary  


.$# * 4 8 A> W@  X[  0. 

Universal Knowledge Solutions s.a.l 98


.0. +$ 8 *8  # + '  ! *7 ! 
,  @  30 +$ 8 / X 9 I0 A> ,     $   ! @
 @  X4  K $ ShowSummary  (4 True   [ @ 7 HeaderText
0. (,8 & *= *$ ! (C $ I
) +$ 8 *+   ErrorMessage 
. 

<asp:ValidationSummary id="valSummary" runat="server"


HeaderText="<b>The following errors were found:</b>"
ShowSummary="True" DisplayMode="List" />

/0. (4  2 + K $G *W  X4      DisplayMode  +


 ForColor   < 2 + .List,BulletList,SingleParagraph)   
.   
,  X4  /0. $ 04 < 2 % # W $2 ShowMessageBox  
. # $# 8 <8 $ ,8  G VW

.$# * 4 8 A> W@  X[  0. 

EnableClientScript " " & 


* ()  5)
 !  #   #

Universal Knowledge Solutions s.a.l 99


Enabledn   @ *    2  (,8 +$   !
   I2 *  +
EnabledClientScript 

Sub Page_Load()
Dim objValidator As BaseValidator
For Each objValidator In Page.Validators
objValidator.Enabled = lstEnabled.SelectedItem.Text
objValidator.EnableClientScript = lstClientScript.SelectedItem.Text
Next
End Sub

8 <
4 

: 
5  

:   
.5  %8@  !
   5   *$  T % $ % + 8 9 W@  @ +$ 8

:!"
.+$ 8  , *# 0. !  

:  # $%&
:(,8 *# 0. !  9 
5   2 •
% $  @ (4 +$ 8  1  9 + •

   8
 (4 +$ 8  + 9 + •
  +$ 8  X4   X ? 9 + •
Universal Knowledge Solutions s.a.l 100

  <
 C  

ASP 58 @ . ,$  ! 5   (4 * (4  5  1@ ,T2 P$
  5  W; 5  8@ *7 5   U2    1 *& 0. G
% .  X4     ,8 5 , G 58 +   5#, XML W7 ! +&
5@ 3,   ,
 *8> /0.  G 
   + , + ASP 1 * + . 
.*, 4 ! % - ! 8 

! 5  % 4 I


 04 .U> *+  5   X4 % - % 
  ASP.NET 5@
1 
1 *,     !  
 +$ 8  ,+ 8
 8 ASP.NET
. XML W7 1 &  W; 5  1   5  8@ U2
1  ($ 
   # +   & *+ *
) += 5        2 .  

.5   +$ 8 
*  + C2 ! .NET *8 4 !  (Off Line) !] T * T  
..  X4 1 * ! 3, 8 5  1 *  ! * 8@

Universal Knowledge Solutions s.a.l 101


:(,8 ,
 /0. ! 9  0

M5   2 •


% $  @ (4 +$ 8  1  9 + •
   8
 (4 +$ 8  + 9 + •
  +$ 8  X4   X ? 9 + •




*7 5  ! Visual basic *7 


  5? ! 8 %  5   2 9  
.Microsoft Access

*7 5  5 $    P0 (,8 +$ 8     !   CG 5   2 9_ R
  @ *+  X4   5;
  3 $, P0  K $ .5  8@ 5;
  8

.+$ 8   H %  *$  @

2    X- !
   I2 + 
$  5;
 8
 ! *$ +$ 8  
.!,> 5   K $

Visual !  (L )   ,    HTTP *+    '& <8
5$ !  9   COM 5+  IE4 '#  0 .Access  Basic
/0.   5 .HTTP *+  1 Access  VB !  3, ,7 5  
G 5, ! 5 X ! 3+=    +   
 5   5+ 5+
.!2 *+=   /0. (,8 8& 8 (4 52 5,

:" 0 9 < )  ;


,     *
 9     5  5
  9;&  4
A 4 W U2 ,T> 8   (4 .NET ! 5 +  5 0  $ T < 2 '#
(,8 5 # 1 
1 2 C  *+=    ?    U $ 5 
.

Universal Knowledge Solutions s.a.l 102


8 A=[  '  > %
  (,8 *8> 1 
% 4  ,8 F 5&$  7+ !
.5  2 %  ' + P   +$
5@  ! C   %#&  
 5   2 (4 .NET W  ! /
& 
8 + Access  VB !  3,  = 5  * 
   +  * ,
.  W + , T W  ! HTTP *+ 


 (-;

 T A=- ADO *7 5  2 5+     f ASP3.0  ! 
..  X4  ! 5  9# I$ recordSet
     P & 9# 8   + ,$ ! * (4 L$# (,8  L  +
:! *7 ! X + P    

...' assuming we've got a Recordset object containing the data ...
Response.Write "<table>"
Response.Write "<tr><th>Date</th>"
Response.Write "<th>Subject</th>"
Response.Write "<th>User Name</th>"
Response.Write "<th>Content</th></tr>"
Do While Not objRecs.EOF
strDate = FormatDateTime(objRecs("dtDate").value, vbLongDate)
Response.Write "<tr><td>" & strDate & "</td>"
Response.Write "<td>" & objRecs("tSubject").value & "</td>"
Response.Write "<td>" & objRecs("tUserName").value & "</td>"
Response.Write "<td>" & objRecs("tContent").value & "</td></tr>"
objRecs.MoveNext
Loop
Response.Write "</table>"
objRecs.Close

:! !
   + !#+ ASP.NET ! * # A>

<!-- the server control located in the HTML section of the page -->
<ASP:DataGrid id="MyDataGrid" runat="server" />
...' assuming we've got a DataView object containing the data ...
MyDataGrid.DataSource = objDataView
MyDataGrid.DataBind()

Universal Knowledge Solutions s.a.l 103


*
A=[  04 :< H ASP 3.0 !
   C  I0 * # AG  +$ 8 
9 *+    I$ ! 9#  ,, <8 *> 9 ! *$ AG HTML
+$ 8 W *  *
   ?  *+ 1  5   !
.ASP:DataGrid
 @ [  9 @  X4 2 5$# (4   2 !H   4 1  *7 *  (,
.!
   (4  2  4 W 

7 ! + % + 5+ A 5   X4 G   + +$ 8 ASP.NET 
. 
 5   *;  30 *+ I
. $ 5  8 1 * 5+ 2 


 (-;

 T A=- ADO *7 5  2 5+     f ASP3.0  ! 
..  X4  ! 5  9# I$ recordSet
     P & 9# 8   + ,$ ! * (4 L$# (,8  L  +
.P    

*
A=[  04 :< H ASP 3.0 !
   C  I0 * # AG  +$ 8 
9 *+    I$ ! 9#  ,, <8 *> 9 ! *$ AG HTML
+$ 8 W *  *
   ?  *+ 1  5   !
9 @  X4 2 5$# (4   2 !H   4 1  *7 *  (, .ASP:DataGrid
.!
   (4  2  4 W   @ [ 

7 ! + % + 5+ A 5   X4 G   + +$ 8 ASP.NET 
. 
 5   *;  30 *+ I
. $ 5  8 1 * 5+ 2 



A 

5     @ %8 2  @ P  ASP.NET *


(,8  
 5   2 
Universal Knowledge Solutions s.a.l 104
.$# ! +$ 8  2 $# (,8

  
 !
   ,+ !  3,  =    > ?  
.5   ?  !. ?  2 (,8 &+ # % =4

<%# name-of-data-source %>

 +  
 !
   ,++   2 1 ,+ /0.  /0 #    1 + &
.,+ /0.  5     5   B + & 30+ 5 

:5   !  2 $  

:   = 

:09 
(4  @ [ T *$+ +$ 8 1    % $  @   + 8 $ /0. F
 (4 .4       F $ /0. ! .+$ 8 W   
,> 0. R .(VALUE  TEXT W ;
< 7) +$ 8 . X  !   8 % 
ASP:HyperLink ASP:TextBox <INPUT> *7 % $  @   X ! +$  <
.

:    = 

: 8 
2 W@  + *7 *  (, . @  7+2 (,8 5   I$ 8   /0. F
. @  7+2  X4 C+ +$ 8 1 9# 8
 2 8

.ASP:CheckBoxList ASP:ListBox <SELECT> *7 +$ 8 $ /0. 

.  !8  U I2   !  > 5  # F *$ *+ (,8

   = 

5  $2 2 W  B$4 2 W $2 *7 % $  @ (4 +$ 8    8
:    c  $2  +
<%# property-name %>

Universal Knowledge Solutions s.a.l 105


2
<%# method-name (parameter1, parameter2,…) %>
2
<%# expression%>
:+$ 8 (4   + !  , ,$  %8 3. 2  c   B  2 +
. H  T ! 2 +$ 8 ! 2 $# !  8 \ _ R    @ •
. H  T ! 2 +$ 8 ! 2 $# !  8 \ _ R     %R    •
.   
 •

ReadOnly Property ImageURL() As String


Get
'read-only property for the Page
Dim strURL As String
'some code would be here to calculate the value
'we just set it to a fixed value for illustration
strURL = "myimage.gif"
Return strURL
End Get
End Property

:+$ 8 (4   + !  , ,$  %8 3.
. H  T ! 2 +$ 8 ! 2 $# !  8 \ _ R    @ •
. H  T ! 2 +$ 8 ! 2 $# !  8 \ _ R     %R    •
.   
 •


   <    " 4

+$ 8 1 ; ,@ 5   ,+ + !      !   $ %  +
. H +$ 8   8  $2  @ (,8 *$ +  B 2

TEXT  [ TextBox +$ 8 (4 LABEL +$ 8  + *7 *  (,
.LABEL +$ 8 ! TEXT ,  + TextBox +$ 

<form runat="server">
<ASP:TextBox id="MyTextBox" runat="server" />

Universal Knowledge Solutions s.a.l 106


<ASP:Label id="MyLabel" Text="<%# MyTextBox.Text %>" runat="server"
/>
<input type="submit" />
</form>
<script language="VB" runat="server">
Sub Page_Load()
DataBind()
End Sub
</script>

+$ 8  %0G LABEL +$ 8 !   + $# * 4    %  *+ !
A8  !
   + B , & * 0. - myTextBox ( TextBox
.DataBind  

8 I2 !  @ P -   < 2 + 04 +$    @ [   /0. $&
:?   ASP:Image +$ 8 ! Src ,  @ A8- *7 *  (, .+$

<ASP:Image Src="<%# ImageURL %>" ImageAlign="middle" runat="server"


/>

: + ASP:HyperLink +$  URL !   $   $
<ASP:Hyperlink Text="<%# ImageURL %>" NavigateUrl="<%# ImageURL %>"
runat="server" />

. ‫ ا>دی‬HTML ‫ ﺵ!ات‬S‫ ﻡ‬7*‫ وﺡ‬HTML   !‫"ﺹ‬# S‫& ﻡ‬3N‫  ﻡ‬N3 "<*‫ ا‬X.‫> ه‬

<input type="text" value="<%# ImageURL %>" />

<input type="submit" value="<%# ImageURL %>" />

<a href="<%# ImageURL %>"><%# ImageURL %></a>

<a href="http://mysite.com/images/<%# ImageURL %>">


View the file named '<%# ImageURL %>'</a>


   <    " 4

+$ 8 1 ; ,@ 5   ,+ + !      !   $ %  +

Universal Knowledge Solutions s.a.l 107


. H +$ 8   8  $2  @ (,8 *$ +  B 2

TEXT  [ TextBox +$ 8 (4 LABEL +$ 8  + *7 *  (,
.LABEL +$ 8 ! TEXT ,  + TextBox +$ 

8 I2 !  @ P -   < 2 + 04 +$    @ [   /0. $&
.+$


  #

+  <T)  K$ ; 8 30   * #  ,8


 $# ! 5   ,+  $ 
.   P - ($# * $ K$
I
& * # I
 04 $# 
 A72 ASP 3 $ *@    ,+ *.4 I
04
.,     *+ * .8

.$#   .     7+2 ! %  DataBind      * #  ,8 I



.Page  ?  DataBind    $#  +$ 8 1 
  L
*7) 5     T 8 1   ,+  *$ ! # % $   !.
.(HTML 5 =G

8 !     0  DataBind      $ +$ 8   L
.5   1 *, <   +$
0  DataBind    +$ 8 ! 5     T  82 9   L
.5   1 *,   (,8 &4  &  +   /0. . ?

:8
.+$ 8  U2 %8  % $   5     # + *7 '

Universal Knowledge Solutions s.a.l 108


@%>Page Language="VB<%"

!>DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN<"


>html><head<
>title>Simple Single-Value Data Binding</title<
>style type="text/css<"
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt{
input {font-family:Tahoma,Arial,sans-serif; font-size:9pt{
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold{
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-
bottom:5px{
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt{
/>style></head<
>body bgcolor="#ffffff<"
>span class="heading">Simple Single-Value Data Binding</span><hr</
<---------------------------------------------------------------------------!>

>form runat="server<"

>table border="0<"
>tr><td nowrap="nowrap<"

>b>&lt;ASP:Label&gt;</b> control:
>ASP:Label Text="<%# ImageURL %>" runat="server" /><p</

>b>&lt;ASP:TextBox&gt;</b> control:
>ASP:TextBox Text="<%# ImageURL %>" runat="server" /><p</

>b>&lt;ASP:Button&gt;</b> control:

Universal Knowledge Solutions s.a.l 109


>ASP:Button Text="<%# ImageURL %>" runat="server" /><p</

>b>&lt;ASP:LinkButton&gt;</b> control:
>ASP:LinkButton Text="<%# ImageURL %>" runat="server" /><p</

>b>&lt;ASP:Image&gt;</b> control:
>ASP:Image Src="<%# ImageURL %>" ImageAlign="middle" runat="server" /><p</

>b>&lt;ASP:CheckBox&gt;</b> control:
>ASP:CheckBox Text="<%# ImageURL %>" runat="server" /><p</

>b>&lt;ASP:RadioButton&gt;</b> control:
>ASP:RadioButton Text="<%# ImageURL %>" runat="server" /><p</

>b>&lt;ASP:Hyperlink&gt;</b> control:
>ASP:Hyperlink Text="<%# ImageURL %>" NavigateUrl="<%# ImageURL %>" runat="server"
/><p</

>b>&lt;ASP:ImageButton&gt;</b> control:
>ASP:ImageButton ImageUrl="<%# ImageURL %>" runat="server</ "

/>td><td nowrap="nowrap">&nbsp; &nbsp; &nbsp;</td><td nowrap="nowrap<"

HTML <b>&lt;span&gt;</b> element:


>span><%# ImageURL %></span><p</

HTML <b>&lt;input type="text"&gt;</b> element:


>input type="text" value="<%# ImageURL %>" /><p</

HTML <b>&lt;input type="submit"&gt;</b> element:


>input type="submit" value="<%# ImageURL %>" /><p</

HTML <b>&lt;button&gt;</b> element:


>button><%# ImageURL %></button><p</

HTML <b>&lt;img&gt;</b> element:


>img src="<%# ImageURL %>" align="middle" /><p</

HTML <b>&lt;input type="checkbox"&gt;</b> element:


>input type="checkbox" /><%# ImageURL %><p</

HTML <b>&lt;input type="radio"&gt;</b> element:


>input type="radio" /><%# ImageURL %><p</

HTML <b>&lt;a&gt;</b> element:


>a href="<%# ImageURL %>"><%# ImageURL %></a><p</

HTML <b>&lt;button&gt;</b> and <b>&lt;img&gt;</b> elements:


>button><img src="<%# ImageURL %>"></button<
Universal Knowledge Solutions s.a.l 110
/>td></tr<
/>table<

/>form<

<---------------------------------------------------------------------------!>

>script language="vb" runat="server<"

ReadOnly Property ImageURL() As String


'declare a read-only property for the Page
Get
Return "myimage.gif"
End Get
End Property

Sub Page_Load()
'bind all the controls on the page
Page.DataBind()
End Sub

/>script<

<---------------------------------------------------------------------------!>

/>body<
/>html<

+  <T)  K$ ; 8 30   * #  ,8


 $# ! 5   ,+  $ 
.   P - ($# * $ K$
I
& * # I
 04 $# 
 A72 ASP 3 $ *@    ,+ *.4 I
04
.,     *+ * .8

.$#   .     7+2 ! %  DataBind      * #  ,8 I



.Page  ?  DataBind    $#  +$ 8 1 
  L
*7) 5     T 8 1   ,+  *$ ! # % $   !.
Universal Knowledge Solutions s.a.l 111
.(HTML 5 =G
8 !     0  DataBind      $ +$ 8   L
.5   1 *, <   +$
0  DataBind    +$ 8 ! 5     T  82 9   L
.5   1 *,   (,8 &4  &  +   /0. . ?

     ? 





 8  .2 7+2 '  + 5   + .% #   % $   5    ,8 F
 2  W;8 5  %8@  9#  8
 *7 .  X4   !    % + 9#
. @ #

 8
 3, K $ % +   1 *,    B
W@ +$ 8 !7 ASP.NET 
2  X4 8 A=[  H %   7 .5   *&   ' !   W
.5    9 *+  X4 9

8    A=[  I0 <SELECT> W@  +$ 8 0G 30 (,8 *7+
.5    9# 1 
 X- <OPTION>

 X- # HTML  I2 + (4    8 !   /0. ! $ 5  $2 ,
4 (,8 %  1 X#$ 1) +$ 8 *@  !H *+= /J=4 I
04   0.
.(
$ $ P    HTML 8

:  
 < #   C  
: 
 5   &   7  !,    
system.web.ui.htmlControls.htmlSelect 9  . <SELECT> +$ 8 •
system.web.ui.WebControls.ListBox 9  I0 ASP:ListBox +$ 8 •
9  I0 ASP:DropDown +$ 8 •
system.web.ui.WebControls.DropDown
9  I0 ASP:CheckBoxList +$ 8 •
system.web.ui.webControls.CheckBoxList
Universal Knowledge Solutions s.a.l 112
9  I0 ASP:RadioButtonList +$ 8 •
system.web.ui.webControls.RadioButtonList
system.web.ui.webControls.Repeter 9  I0 ASP:Repeter +$ 8 •
system.web.ui.webControls.DataList 9  I0 ASP:DataList +$ 8 •
system.web.ui.webControls.DataGrid 9  I0 ASP:DataGrid +$ 8 •


 8  .2 7+2 '  + 5   + .% #   % $   5    ,8 F
 2  W;8 5  %8@  9#  8
 *7 .  X4   !    % + 9#
. @ #

 8
 3, K $ % +   1 *,    B
W@ +$ 8 !7 ASP.NET 
2  X4 8 A=[  H %   7 .5   *&   ' !   W
.5    9 *+  X4 9

8    A=[  I0 <SELECT> W@  +$ 8 0G 30 (,8 *7+
.5    9# 1 
 X- <OPTION>

 X- # HTML  I2 + (4    8 !   /0. ! $ 5  $2 ,
4 (,8 %  1 X#$ 1) +$ 8 *@  !H *+= /J=4 I
04   0.
.(
$ $ P    HTML 8

:  
 < #   C  
: 
 5   &   7  !,    
system.web.ui.htmlControls.htmlSelect 9  . <SELECT> +$ 8 •
system.web.ui.WebControls.ListBox 9  I0 ASP:ListBox +$ 8 •
9  I0 ASP:DropDown +$ 8 •
system.web.ui.WebControls.DropDown

Universal Knowledge Solutions s.a.l 113


9  I0 ASP:CheckBoxList +$ 8 •
system.web.ui.webControls.CheckBoxList
9  I0 ASP:RadioButtonList +$ 8 •
system.web.ui.webControls.RadioButtonList
system.web.ui.webControls.Repeter 9  I0 ASP:Repeter +$ 8 •
system.web.ui.webControls.DataList 9  I0 ASP:DataList +$ 8 •
system.web.ui.webControls.DataGrid 9  I0 ASP:DataGrid +$ 8 •

  
    !C"

% -   W  8


  K $  
  & +$ 8   B

:W /0  $W& !,     .   ,8

$ "
  (,8 I$ I0 5   8 2 *$ $ DataTextField
   *7 *  (,8 ..  X- F  !
, +<OPTION> +$ 8 
ListBox.
!   I$ I0 5   8 2 *$ $ DataValueField
 *
2  F VALUE   !
 !    *7 *  (,8 .+$ 
VALUE  <OPTION> +$  
ListBox.
 %$   1  9 $ ,,   $ DataTextFormatSt
ring
 C 4 =R *$ 2 DataTextList 8
 *7 *  (,8 .     /0.  X4
‘{0:C}’ 2 ,   ‘{0:dddd MMMM
dd,yyyy}’.f   
A$ 8       ! 9# 8
 $ DataMember
*  (,8 .9# 8
  7+2 (,8 5  
 T 1   8 *
  *7DataSet.
Universal Knowledge Solutions s.a.l 114
 
    B& :

5  1 ; *@> (,8   ‘% +   1 *, F +$ 8 1 

: 
$  
  5  +$ 8 A*
  * #  I2 5  
DataBind
8 '  A72 C @ I0
.+$ 8
+$ 8 (4 =J %&  R
FindControl
.  +$ 8  &

: 
   #
" B9
+$ 8 U   , W@ +$ 8   @;4  ! K$d 1 *
 3.
:5     W +$ 8 U2  + = 7$ 3. *$ *+ (,8.
9 K$
! 9 *+ *
2  K$ 0. X
9 B$   .5  
K $ K$ 5;  K$ (4 DataBinding
A72 9 5  *  $ +
.5, +$ 8 A*
$# * 4  8 K$ 0. X
. ‘ (4 %   1
SelectedindexChange
5 ? A
[ !
  , '
. 5   +  X- (,8

    
 
 

Universal Knowledge Solutions s.a.l 115


 U 0    + ! 5   !,     +$ 8 (,8 ,
m  2 
. 

 ! 5    U I2 (4 W +$ 8   #  $  +
W +$ 8
^ 2  ,  $  ! 0. . IListSource 2 ICollection IEnumerable
:(4   +
 T ! *
 8
 2 Request.Form 6    8
 *7 Collection •
#G .G=F 8
 I2 2 Dataset
 X4   + 04 <8 %
  !. .     8
 I$ !. :ArrayList •
;
< 7 ListBox ! 5  
+ .Dictionary  ? *$+ \# 8  4 * + 8 I$ :HashTable •
9, K $ W +$ 8 $ !  7 /0. 5   *
  @ \# 8 *+
8   8  84     8 /  X4   
  , .G I
DataTable  T2  9# (,8  ? 0. I$ :DataView  T •
!
     8 <   , .G .J=4 I
2 5  %8@
+ .5  %8@ 1 $ /
 %A ,  *  I0 :DataReader  T •
. Dataview  T 1 *$   = %  C *   9# 8
 2 9 I$ 2
! U 2 DataReader  ? A2 + K $ A>  T> DataReader  ? %< 8 
5&$ ,T2

     



" 4 A 

Universal Knowledge Solutions s.a.l 116


:?     %   1   2  1   *$+ % $   +$ 8  8

<%# name-of-data-source %>

U  5   + *$ !# .*$  7+2 (,8 % +     5   I$
@ + 2
DataReader U  + 2  @ \# (,8 I$ I0 HashTable
.C 4 +$ 8    *$ 2   $ (,8

*  (, .W ! 8 *+  @  7+2  X4 (,8 % @ W +$ 8  7+ +
,  @ <OPTION>  B$  @  <SELECT>  ! 1  *7
.  0  VALUE
<Select>
<Option Value=”Value1”> Text1</Option>
<Option Value=”Value2”> Text2</Option>
</Select>

:   !C" 0 


    4;
.+$ 8 W (4 5   ! 9 *+  $ *$ * 2 -   3.
:C   I0 +$ 8 (,8     
8 *@  /  X4   9 *+ @ 8 '  +  8 +$ 8 + 04 L
.+$
8 W (4 5   ! *$ 4 1   8 & +$ 8 + 04 L
.V  *8 A72 W  +$

DataGrid  DataList Repeater :!.  8 ! ASP.NET ! +$ 8 +
.C 5   5 , 1 @ 8 '   /0.  I> + C ,8

Key:<%# Container.DataItem.Key%>
2
Value:<%Container.DataItem.Value%>
 2 *$  $ DataReader 2 DataView 2 Collection  T2 1   8
:C#

Universal Knowledge Solutions s.a.l 117


Value from DataView/DataReader: <%# Container.DataItem (“bookName”)
%>
2
Value from Collection: <%# Container.DataIem(“forColor”) %>

:HashTable  T  Value  Key  @  X- Repeater +$ 8  1  ;


< 7
<ASP:Repeater id="MyRepeater" runat="server">
<ItemTemplate>
<%# Container.DataItem.Key %> =
<%# Container.DataItem.Value %><br />
</ItemTemplate>
</ASP:Repeater>

     



" 4 A 

.   %   1   2  1   *$+ % $   +$ 8  8

U  5   + *$ !# .*$  7+2 (,8 % +     5   I$
@ + 2
DataReader U  + 2  @ \# (,8 I$ I0 HashTable
.C 4 +$ 8    *$ 2   $ (,8

*  (, .W ! 8 *+  @  7+2  X4 (,8 % @ W +$ 8  7+ +
,  @ <OPTION>  B$  @  <SELECT>  ! 1  *7
.  0  VALUE

:   !C" 0 


    4;
.+$ 8 W (4 5   ! 9 *+  $ *$ * 2 -   3.
:C   I0 +$ 8 (,8     
8 *@  /  X4   9 *+ @ 8 '  +  8 +$ 8 + 04 L
.+$
8 W (4 5   ! *$ 4 1   8 & +$ 8 + 04 L
.V  *8 A72 W  +$

Universal Knowledge Solutions s.a.l 118


DataGrid  DataList Repeater :!.  8 ! ASP.NET ! +$ 8 +
.C 5   5 , 1 @ 8 '   /0.  I> + C ,8

# F8&     


  & 4;

/0. $ * A72 W  @   &   8 & ! +$ 8  8
(DataTextField ) P  ! /  X4   I0 5    *$  W
.(DataValueField ) +$  % .X T   !  I0 *$
<select id="MySelectList" runat="server" />

:!
   Page_Load K$ V ! 9  7

MySelectList.DataSource = tabValues
MySelectList.DataValueField = "Key"
MySelectList.DataTextField = "Value"
MySelectList.DataBind()

 X4  H %  5    *$  $ !+ *+= < +0 DataGrid +$ 8  
 DataSet DataView Array . 5   + 8 *$ 0. * .  1 

.HashTable . 5   + *$ ! * & + DataReader

# F8&     


  & 4;

/0. $ * A72 W  @   &   8 & ! +$ 8  8
(DataTextField ) P  ! /  X4   I0 5    *$  W
.(DataValueField ) +$  % .X T   !  I0 *$

 X4  H %  5    *$  $ !+ *+= < +0 DataGrid +$ 8  
 DataSet DataView Array . 5   + 8 *$ 0. * .  1 

Universal Knowledge Solutions s.a.l 119


.HashTable . 5   + *$ ! * & + DataReader

Eval  

#   

5= 2 !   ,72   ! +$ 8 ! 5   ,+ I$ 2 +
: 8
<%# Container.DataItem (“FieldName”) %>

  @  $ W= 5= $2 DataBinder  ?  Eval    R
..  X-       '  .9   @  7+2 (,8 CW$ *$ ! 5  

:Eval      1  *W K;7 3.


.(8 2 *$  7+2)  @  7+2 (,8 5    W  9 *+ A$ 8 L
.HashTable  T 2 5  %8@  *
   DataView  9 *7 *  (,8
. , + +$    30 8 9,  T  T  8 L
.,+     8  @ 02 *7 *  (,8 ..  X4 8  @     8 L

B <W =  ,8 9  & <  ? , <     (>   
 T ! 9  BookTitle (       ! *7 ! .A> U
:DataView
<%# DataBinder.Eval (Container.DataItem,”BookTitle”) %>
  (4  (,82 *$ ,      G   (8   Eval   
.   ,

 ! 9  T  T (4     8 SQF Eval &  7   2


*+ !      ? 0. !    @ (4 =G 30  ' .+$  DataSource
I$ ObjCityData  DataView  T   + 04 *7 *  (, ./  X4  9
DataView  ?  1  9 ! CityName   @  $ 1   *$ 5,
:

<%# DataBinder.Eval(ObjCityData, “[3].CityName”) %>


Universal Knowledge Solutions s.a.l 120
$ = ! /   0. .  X4         %W Eval   5  7+2 
. 

  @  $ W= 5= $2 DataBinder  ?  Eval    R
..  X-       '  .9   @  7+2 (,8 CW$ *$ ! 5  

:Eval      1  *W K;7 3.


.(8 2 *$  7+2)  @  7+2 (,8 5    W  9 *+ A$ 8 L
.HashTable  T 2 5  %8@  *
   DataView  9 *7 *  (,8
. , + +$    30 8 9,  T  T  8 L
.,+     8  @ 02 *7 *  (,8 ..  X4 8  @     8 L

B <W =  ,8 9  & <  ? , <     (>   
.A> U
  (4  (,82 *$ ,      G   (8   Eval   
.   ,

 ! 9  T  T (4     8 SQF Eval &  7   2


*+ !      ? 0. !    @ (4 =G 30  ' .+$  DataSource
./  X4  9

$ = ! /   0. .  X4         %W Eval   5  7+2 
. 

:EVal  " 4
  : 4

T P    $ I0 formatString .   > + 5; K;7 Eval   0G
 I0 5    PublicationField *$ B$  $ 1  *7 *  (, .I 
4
:?   !X f    /  X4

Universal Knowledge Solutions s.a.l 121


<%# DataBinder.Eval(Container.DataItem, "PublicationDate", "{0:D}")
%>

.(,   ,@- 58- $) “10 july 2006” *+=  


 +

@  + 2
K $  *+ ! % $  @ (,8 *$ 1  Eval    8
9 $ 2  (       *$  I0 ?, + 
$  ) <W < #   *>
. ,   8  I0   !

: 5  .2   !,  

:  5 


" 4 $ 
8 $
: 4 
$1,234.60, ($28.15), Currency format C or c
205, 17534, -65 Decimal format D or d
Scientific
3.46E+21, -1.2e+3,
(exponential) E or e
3.003E-15
format
34.300, -0.230 Fixed-point format F or f
Depends on actual value General format G or g
3,456.23, 12.65, -1.534 Number format N or n
45.6%, -10% Percent format P or p
&H5f76, 0x4528 (depends Hexadecimal
X or x
on actual value) format

:" 42 M   < &


" 4 $ 
8 $
: 4 
M/d/yyyy Short date d
dddd, MMMM dd, yyyy Long date D
dddd, MMMM dd, yyyy Full (long date and
f
HH:mm aa short time)
dddd, MMMM dd, yyyy Full (long date and
F
HH:mm:ss aa long time)
General (short
g
M/d/yyyy HH:mm aa date and short
time)

Universal Knowledge Solutions s.a.l 122


General (short
M/d/yyyy HH:mm:ss aa date and long G
time)
MMMM dd Month and day M or m
ddd, dd MMM yyyy
RFC1123 format R or r
HH:mm:ssGMT
ISO 8601 sortable
yyyy-MM-dd HH:mm:ss s
using local time
HH:mm aa Short time t
ISO 8601 sortable
yyyy-MM-dd HH:mm:s using universal u
time
dddd, MMMM dd, yyyy Universal sortable
U
HH:mm:ss aa date/time
MMMM, yyyy Y or y
Year and month

   *7 *  (,  @   %  A=- ! *


 ! 9 $  < 2 + 
 2 
  @  $   + 0[ ."001.23" @  1.2345 @  (,8   8 "00#.##"
. ,     8  ,#  [  #

:*+=    % 8  <04


“00#.##;(00#.##);[0]”
(,8 *$ 1 
. # @ , “[0]”  -1.2345 @ , “(001.23)”
9   9 $
2  @ 3. +  04 #  X[ 
#2 $ 2 @  2 i  # 9  0
. = ,#   4  =8
0   X I2 *  @ I2 C,$ *$
#
  @ 
  04 9 $
 =8  X .
% 9 $ X %
E+0, E-0,
 P    Scientific 2
e+0 or e-0
E

? !. + . 9 $  X[  \

Universal Knowledge Solutions s.a.l 123


.  9 $  + 8 X
+ %$ 9 $ 8
 I2  X4 
9 $  + 8 X ? !. !. “ 2 ‘
. 

T P    $ I0 formatString .   > + 5; K;7 Eval   0G
.I 
4

   /J, /J=4  ArrayList  I


.% +   5   8 *71.7-8.16
:Page_Load K$ V

Universal Knowledge Solutions s.a.l 124


.W@ +$ 8 !7 8 '  @ 2 $# /0   html A
! X$;
.DataList  Repeater 8   30  J +
:C# +$ 8 9  . C,#  *+

HTML <b>&lt;select&gt;</b> element:<br />


<select id="MySelectList" runat="server" /><p />
<b>&lt;ASP:DropDownList&gt;</b> control:<br />
<ASP:DropDownList id="MyDropDown" runat="server" /><p />
<b>&lt;ASP:ListBox&gt;</b> control:<br />
<ASP:ListBox id="MyASPList" runat="server" /><p />
<b>&lt;ASP:DataGrid&gt;</b> control:<br />
<ASP:DataGrid id="MyDataGrid" runat="server" /><p />
<b>&lt;ASP:Repeater&gt;</b> control:<br />
<ASP:Repeater id="MyRepeater" runat="server">
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</ASP:Repeater><p />
<b>&lt;ASP:DataList&gt;</b> control:<br />
<ASP:DataList id="MyDataList" runat="server">
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</ASP:DataList><p />
<b>&lt;ASP:CheckBoxList&gt;</b> control:<br />
<ASP:CheckBoxList id="MyCheckList" runat="server" /><p />
<b>&lt;ASP:RadioButtonList&gt;</b> control:<br />
<ASP:RadioButtonList id="MyRadioList" runat="server" /><p />

@ 30 % + ,   I0 P   $ ,   Datalist  Repaeater (4  2
. <ItempTemplate> P [

 !  .% +   /0 # I


 <ItempTemplate>  C
  + < 2
.ArrayList   0    1  C# 5  8  $ !
 
.J, ArrayList A=[   $# * $ K$ 
  !
  , 
 DataSource ,  + ArrayList  ? [  9 $ *;   @ 
.5     7 .+$
Sub Page_Load()
'create an ArrayList of values to bind to
Dim arrValues As New ArrayList(4)
arrValues.Add("Microsoft")
arrValues.Add("Sun")
arrValues.Add("IBM")

Universal Knowledge Solutions s.a.l 125


arrValues.Add("Compaq")
arrValues.Add("Oracle")
'set the DataSource propert of the controls to the array
MySelectList.DataSource = arrValues
MyDropDown.DataSource = arrValues
MyASPList.DataSource = arrValues
MyDataGrid.DataSource = arrValues
MyRepeater.DataSource = arrValues
MyDataList.DataSource = arrValues
MyCheckList.DataSource = arrValues
MyRadioList.DataSource = arrValues
'bind all the controls on the page
Page.DataBind()
End Sub

HashTable " 4    


 8

Universal Knowledge Solutions s.a.l 126


.W@ +$ 8 !7 8 '  @ 2 X$; $# /0   html A
!
.DataList  Repeater 8   30  J +
:C# +$ 8 9  . C,#  *+

HTML <b>&lt;select&gt;</b> elements:<br />


<select id="MySelectList1" runat="server" /> &nbsp;
<select id="MySelectList2" runat="server" /><p />
<b>&lt;ASP:DropDownList&gt;</b> controls:<br />
<ASP:DropDownList id="MyDropDown1" runat="server" /> &nbsp;
<ASP:DropDownList id="MyDropDown2" runat="server" /><p />
<b>&lt;ASP:ListBox&gt;</b> controls:<br />
<ASP:ListBox id="MyASPList1" runat="server" /> &nbsp;
<ASP:ListBox id="MyASPList2" runat="server" /><p />
<b>&lt;ASP:DataGrid&gt;</b> control:<br />
<ASP:DataGrid id="MyDataGrid" runat="server" AutoGenerateColumns="false">
Universal Knowledge Solutions s.a.l 127
<Columns>
<ASP:BoundColumn HeaderText="Key" DataField="Key" />
<ASP:BoundColumn HeaderText="Value" DataField="Value"
DataFormatString="{0:C}" />
</Columns>
</ASP:DataGrid><p />
<b>&lt;ASP:Repeater&gt;</b> control:<br />
<ASP:Repeater id="MyRepeater" runat="server">
<ItemTemplate>
<%# Container.DataItem.Key %> =
<%# Container.DataItem.Value %><br />
</ItemTemplate>
</ASP:Repeater><p />
<b>&lt;ASP:DataList&gt;</b> control:<br />
<ASP:DataList id="MyDataList" runat="server">
<ItemTemplate>
'<%# Container.DataItem.Key %>'- value:
<%# DataBinder.Eval(Container.DataItem, "Value", "{0:E}") %>
</ItemTemplate>
</ASP:DataList><p />
<b>&lt;ASP:CheckBoxList&gt;</b> control:<br />
<ASP:CheckBoxList id="MyCheckList" runat="server" /><p />
<b>&lt;ASP:RadioButtonList&gt;</b> control:<br />
<ASP:RadioButtonList id="MyRadioList" runat="server" /><p />
<ASP:DataGrid id="MyDataGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<ASP:BoundColumn HeaderText="Key" DataField="Key" />
<ASP:BoundColumn HeaderText="Value" DataField="Value"
DataFormatString="{0:C}" />
</Columns>
</ASP:DataGrid>

.<itemTemplate>  DataList  Repeater 8   


.HashTable 1 * + Value 5  8 Key 5    X$;
<b>&lt;ASP:Repeater&gt;</b> control:<br />
<ASP:Repeater id="MyRepeater" runat="server">
<ItemTemplate>
<%# Container.DataItem.Key %> =
<%# Container.DataItem.Value %><br />
</ItemTemplate>
</ASP:Repeater><p />
<b>&lt;ASP:DataList&gt;</b> control:<br />
<ASP:DataList id="MyDataList" runat="server">
<ItemTemplate>
'<%# Container.DataItem.Key %>'- value:
<%# DataBinder.Eval(Container.DataItem, "Value", "{0:E}") %>
</ItemTemplate>
</ASP:DataList><p />

:Page_Load K$ V  5  HashTable  T A* < 2 


Sub Page_Load()
'create a HashTable of values to bind to
Dim tabValues As New HashTable(5)
tabValues.Add("Microsoft", 49.56)

Universal Knowledge Solutions s.a.l 128


tabValues.Add("Sun", 28.33)
tabValues.Add("IBM", 55)
tabValues.Add("Compaq", 20.74)
tabValues.Add("Oracle", 41.1)
'first <select> displays the Keys in the HashTable
MySelectList1.DataSource = tabValues
MySelectList1.DataTextField = "Key"
'second one displays the Values in the HashTable
'and uses the Keys as the <option> values
MySelectList2.DataSource = tabValues
MySelectList2.DataValueField = "Key"
MySelectList2.DataTextField = "Value"
'same applies to ASP: controls, except here
'we can also specify the format of the Key
MyDropDown1.DataSource = tabValues
MyDropDown1.DataTextField = "Key"
MyDropDown2.DataSource = tabValues
MyDropDown2.DataValueField = "Key"
MyDropDown2.DataTextField = "Value"
MyDropDown2.DataTextFormatString = "{0:F}"
MyASPList1.DataSource = tabValues
MyASPList1.DataTextField = "Key"
MyASPList2.DataSource = tabValues
MyASPList2.DataValueField = "Key"
MyASPList2.DataTextField = "Value"
MyASPList2.DataTextFormatString = "{0:C}"

ItemTemplate  $ >  5   DataList  Repeater +$  $ 
.5 $  X4   9 +
MyDataGrid.DataSource = tabValues
MyRepeater.DataSource = tabValues
MyDataList.DataSource = tabValues

W  $ !#+  RadioButtonList  CheckBoxList +$   2


:  DataTextField  DataValueField
'in the CheckboxList we'll display the Title and
'use the Value as the control value
MyCheckList.DataSource = tabValues
MyCheckList.DataValueField = "Value"
MyCheckList.DataTextField = "Key"
'in the RadioList we'll display and format the
'Value and use the Key as the control value
MyRadioList.DataSource = tabValues
MyRadioList.DataValueField = "Key"
MyRadioList.DataTextField = "Value"
MyRadioList.DataTextFormatString = "Percentage rate {0:F}%"

$# !  1 
  ,8 ( &2
1 
Page.DataBind() 'bind all the controls on the page
End Sub

:DataView @ E 0;     =
8

Universal Knowledge Solutions s.a.l 129


 $+   ? 0. 1 * .Dataview  T (4 5     *7 0. !
5  (,8 *$  # + 5  8@ 1 *& 8 K $ *
J > 9#  8

. ? 0   ,
(4  

<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>


<%@ Register TagPrefix="wrox" TagName="getdataview" Src="..\global\get-dataview-
control.ascx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Repeated-Value Data Binding to a DataView Object</title>
<style type="text/css">
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
input {font-family:Tahoma,Arial,sans-serif; font-size:9pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
Universal Knowledge Solutions s.a.l 130
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-
bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
</style></head>
<body bgcolor="#ffffff">
<span class="heading">Repeated-Value Data Binding to a DataView Object</span><hr />
<!--------------------------------------------------------------------------->

<%'-- insert the control that creates the DataSet --%>


<wrox:getdataview id="ctlDataView" runat="server"/>

<form runat="server">

HTML <b>&lt;select&gt;</b> elements:<br />


<select id="MySelectList" runat="server" /><p />

<b>&lt;ASP:DropDownList&gt;</b> controls:<br />


<ASP:DropDownList id="MyDropDown" runat="server" /><p />

<b>&lt;ASP:ListBox&gt;</b> controls:<br />


<ASP:ListBox id="MyASPList" runat="server" /><p />

<b>&lt;ASP:DataGrid&gt;</b> control:<br />


<ASP:DataGrid id="MyDataGrid" runat="server" /><p />

<b>&lt;ASP:Repeater&gt;</b> control:<br />


<ASP:Repeater id="MyRepeater" runat="server">
<ItemTemplate>
<div>
<b><%# Container.DataItem("Title") %></b><br />
ISBN: <%# Container.DataItem("ISBN") %> &nbsp;
Published: <%# DataBinder.Eval(Container.DataItem, "PublicationDate", "{0:D}") %>
</div>
</ItemTemplate>
</ASP:Repeater><p />
<b>&lt;ASP:DataList&gt;</b> control:<br />
<ASP:DataList id="MyDataList" runat="server">
<ItemTemplate>
<b><%# Container.DataItem("Title") %></b><br />
ISBN: <%# Container.DataItem("ISBN") %> &nbsp;
Published: <%# DataBinder.Eval(Container.DataItem, "PublicationDate", "{0:D}") %>
</ItemTemplate>
</ASP:DataList><p />

<b>&lt;ASP:CheckBoxList&gt;</b> control:<br />


<ASP:CheckBoxList id="MyCheckList" runat="server" /><p />

<b>&lt;ASP:RadioButtonList&gt;</b> control:<br />


<ASP:RadioButtonList id="MyRadioList" runat="server" /><p />

</form>
Universal Knowledge Solutions s.a.l 131
<!--------------------------------------------------------------------------->

<script language="vb" runat="server">

Sub Page_Load()

'get connection string from web.config


Dim strConnect As String = ConfigurationSettings.AppSettings("DsnWroxBooksOleDb")

'create a SQL statement to select some rows from the database


Dim strSelect As String
strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '07645438%'"

'create a variable to hold an instance of a DataView object


Dim objDataView As DataView

'get DataView from get-dataview-control.ascx user control


objDataView = ctlDataView.GetDataView(strConnect, strSelect)

If IsNothing(objDataView) Then Exit Sub

'set the DataSource property of the controls

'<select> list displays values from the Title column


'and uses the ISBN as the <option> values
MySelectList.DataSource = objDataView
MySelectList.DataValueField = "ISBN"
MySelectList.DataTextField = "Title"

'do same with ASP: list controls


MyDropDown.DataSource = objDataView
MyDropDown.DataValueField = "ISBN"
MyDropDown.DataTextField = "Title"

MyASPList.DataSource = objDataView
MyASPList.DataValueField = "ISBN"
MyASPList.DataTextField = "Title"

'a DataGrid can figure out the columns in the DataView


'by itself, so we just set the DataSource property
MyDataGrid.DataSource = objDataView

'the Repeater and DataList require <ItemTemplate> entries


'that specify the columns - this is done within the element
'definition earlier in the page
MyRepeater.DataSource = objDataView
MyDataList.DataSource = objDataView

'in the CheckboxList we'll display the Title and


'use the Value as the control value
Universal Knowledge Solutions s.a.l 132
MyCheckList.DataSource = objDataView
MyCheckList.DataValueField = "ISBN"
MyCheckList.DataTextField = "Title"

'in the RadioList we'll display and format the


'Value and use the Key as the control value
MyRadioList.DataSource = objDataView
MyRadioList.DataValueField = "ISBN"
MyRadioList.DataTextField = "PublicationDate"
MyRadioList.DataTextFormatString = "Published on {0:dddd, MMMM dd, yyyy}"

'finally, bind all the controls on the page


Page.DataBind()

End Sub

</script>

<!--------------------------------------------------------------------------->
</body>
</html>

Universal Knowledge Solutions s.a.l 133


:DataReader @ E 0;     =
8
 $+   ? 0. 1 * .DataReader  T (4 5     *7 0. !
5  (,8 *$  # + 5  8@ 1 *& 8 K $ *
J > 9#  8

. ? 0   ,
(4  

<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>


<%@Import Namespace="System.Data.OleDb" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Repeated-Value Data Binding to a DataReader Object</title>
<style type="text/css">
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
input {font-family:Tahoma,Arial,sans-serif; font-size:9pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-
bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
Universal Knowledge Solutions s.a.l 134
</style></head>
<body bgcolor="#ffffff">
<span class="heading">Repeated-Value Data Binding to a DataReader Object</span><hr />
<!--------------------------------------------------------------------------->

<div id="outError" runat="server" />

<!-- Unlike the DataView we can only bind a object DataReader to one control -->
<!-- after it has bound the data the reader is at the end of the source rowset -->
<b>&lt;ASP:DataGrid&gt;</b> control:<br />
<ASP:DataGrid id="MyDataGrid" runat="server" /><p />

<!--------------------------------------------------------------------------->

<script language="vb" runat="server">

Sub Page_Load()

'get connection string from web.config


Dim strConnect As String = ConfigurationSettings.AppSettings("DsnWroxBooksOleDb")

'create a SQL statement to select some rows from the database


Dim strSelect As String
strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '07645437%'"

'create a variable to hold an instance of a DataReader object


Dim objDataReader As OleDbDataReader

Try

'create a new Connection object using the connection string


Dim objConnect As New OleDbConnection(strConnect)

'open the connection to the database


objConnect.Open()

'create a new Command using the connection object and select statement
Dim objCommand As New OleDbCommand(strSelect, objConnect)

'execute the SQL statement against the command to get the DataReader
objDataReader = objCommand.ExecuteReader()

Catch objError As Exception

'display error details


outError.InnerHtml = "<b>* Error while accessing data</b>.<br />" _
& objError.Message & "<br />" & objError.Source & "<p />"
Exit Sub ' and stop execution

End Try

Universal Knowledge Solutions s.a.l 135


'set the DataSource property of the control
'a DataGrid can figure out the columns in the DataReader
'by itself, so we just set the DataSource property
MyDataGrid.DataSource = objDataReader
MyDataGrid.DataBind() 'and bind the control

End Sub

</script>

<!--------------------------------------------------------------------------->
</body>
</html>

 9 < #


  !  T  ,8 !. 5    ,8 2 9 + ,
 /0. *;   ,
 *;  2
.,  
   + (4 
$ *, 
  9 +  2 

0. (4 * + 04 . , X 5  P 4  # + . A


 0. ! C 4    +
:  K;7  ?
2 $# ! <Style> % =G   8 2 %< = 4 +$ 8 (4 CSS 2 4 L
.+$  Style  (4  @ [
.+$ 8 P   #, 1 !  X-   $ @ A=4 L
.     V   L

   0; CSS & 2;


:style % =G    8 % =  +$ +
<style type="text/css">
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
input {font-family:Tahoma,Arial,sans-serif; font-size:9pt}
</style>

 P0 +$ 8 *+ (4 4 <input>  !  1 
0G  *7 !
.input ! $  

Universal Knowledge Solutions s.a.l 136


:  # Style " " 4
*   + ! W  8
 (,8 5  1  ,  W +$ 8 X I
A7 $# !  X ? % > /0.  + .$# !  >
.Repeater +$ 8

:/2 *
 ! X   + ! W 
$ "
+$   #, X   BackColor, BackImageUrl

+$ 8 4   BorderStyle, BorderColor, BorderWidth

 , X   GridLines, CellPadding, CellSpacing

+$ 8 !   $ Font-Name, Font-Size, Font-Bold

P   #, A
>  $ HeaderStyle, ItemStyle, FooterStyle
AlternatingItemStyle
.  * 0 2 + +$ 8

  !  T  ,8 !. 5    ,8 2 9 + ,


 /0. *;   ,
 *;  2
.,  
   + (4 
$ *, 
  9 +  2 

0. (4 * + 04 . , X 5  P 4  # + . A


 0. ! C 4    +
:  K;7  ?
2 $# ! <Style> % =G   8 2 %< = 4 +$ 8 (4 CSS 2 4 L
.+$  Style  (4  @ [
.+$ 8 P   #, 1 !  X-   $ @ A=4 L
.     V   L

   0; CSS & 2;


.style % =G    8 % =  +$ +

Universal Knowledge Solutions s.a.l 137


:  # Style " " 4
*   + ! W  8
 (,8 5  1  ,  W +$ 8 X I
A7 $# !  X ? % > /0.  + .$# !  >
.Repeater +$ 8

 9 < #

:  # > " (-; 


  Css " 4 0 8
:/2 !
  , P  . ! *+=

:5)
 !

<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>


<%@Import Namespace="System.Data.OleDb" %>

<%@ Register TagPrefix="wrox" TagName="getdataview" Src="..\global\get-dataview-


control.ascx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Using CSS to Add Style to a DataGrid</title>
<style type="text/css">
body {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
Universal Knowledge Solutions s.a.l 138
input {font-family:Tahoma,Arial,sans-serif; font-size:9pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-
bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
</style></head>
<body bgcolor="#ffffff">
<span class="heading">Using CSS to Add Style to a DataGrid</span><hr />
<!--------------------------------------------------------------------------->

<div id="outError" runat="server" />

<ASP:DataGrid id="MyDataGrid" runat="server"


ShowHeader = "True"
ShowFooter = "False"
BackColor = "darkgray"
BackImageUrl = "background.gif"
ToolTip = "A List of Wrox Books"
GridLines = "None"
BorderStyle = "Solid"
BorderColor = "black"
BorderWidth = "3"
CellPadding = "2"
CellSpacing = "2"
Font-Name = "Comic Sans MS"
Font-Size = "10pt"
Font-Bold = "True" >
<HeaderStyle ForeColor = "blue" />
<ItemStyle ForeColor = "red" />
<AlternatingItemStyle ForeColor = "green" />
</ASP:DataGrid>

<!--------------------------------------------------------------------------->

<script language="vb" runat="server">

Sub Page_Load()

'get connection string from web.config


Dim strConnect As String = ConfigurationSettings.AppSettings("DsnWroxBooksOleDb")

'create a SQL statement to select some rows from the database


Dim strSelect As String
strSelect = "SELECT * FROM BookList WHERE Title LIKE '%ASP%'"

'create a variable to hold an instance of a DataReader object


Dim objDataReader As OleDbDataReader

Try

'create a new Connection object using the connection string


Universal Knowledge Solutions s.a.l 139
Dim objConnect As New OleDbConnection(strConnect)

'open the connection to the database


objConnect.Open()

'create a new Command using the connection object and select statement
Dim objCommand As New OleDbCommand(strSelect, objConnect)

'execute the SQL statement against the command to get the DataReader
objDataReader = objCommand.ExecuteReader()

Catch objError As Exception

'display error details


outError.InnerHtml = "<b>* Error while accessing data</b>.<br />" _
& objError.Message & "<br />" & objError.Source & "<p />"
Exit Sub ' and stop execution

End Try

'set the DataSource property of the DataGrid


MyDataGrid.DataSource = objDataReader

'and bind the control to the data


MyDataGrid.DataBind()

End Sub

</script>

<!--------------------------------------------------------------------------->
</body>
</html>


    <  " 4

9  (4 @ 4 ! W +$ 8 P   X +$,  7   ,
.+$ 8
.   X4   9 + .  X4   ! %8>  $  2 , +

DataGridDataListRepeater:  !.   +$ 8  7;7 *


*+  B$  X-   $ !   8
  /0. 1  2 +
.P   A

Universal Knowledge Solutions s.a.l 140


:   $ 8
   !,  

SelectedItemTemplate #  ( +  #  A2 #


..   I
!   X4   *> $ K $ EditItemTemplate 
.  @ $ I
!   X4    $    !7 2

9  (4 @ 4 ! W +$ 8 P   X +$,  7   ,
.+$ 8
.   X4   9 + .  X4   ! %8>  $  2 , +

DataGridDataListRepeater:  !.   +$ 8  7;7 *


*+  B$  X-   $ !   8
  /0. 1  2 +
.P   A

Universal Knowledge Solutions s.a.l 141


:Repeater   < 4
= " 4  8

:5)
 !
<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Using a Simple Template with a Repeater Control</title>
<style type="text/css">
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
input {font-family:Tahoma,Arial,sans-serif; font-size:9pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-
bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}

Universal Knowledge Solutions s.a.l 142


.rHead {font-family:Lucida Handwriting,Comic Sans MS,Tahoma,Arial;
font-size:14pt; font-weight:bold; padding:8px; color:green}
.rItem {font-family:Lucida Handwriting,Comic Sans MS,Tahoma,Arial,sans-serif;
font-size:10pt}
.rFoot {font-family:Tahoma,Arial; font-size:8pt; padding:8px; color:darkgray}

</style></head>
<body bgcolor="#ffffff">
<span class="heading">Using a Simple Template with a Repeater Control</span><hr />
<!--------------------------------------------------------------------------->

<ASP:Repeater id="MyRepeater" runat="server">

<HeaderTemplate>
<div class="rHead">
Some of the Latest Wrox Books from Wiley<br />
<img src="images/redrule.gif">
</div>
</HeaderTemplate>

<ItemTemplate>
<div class="rItem">
<img src="images/<%# Container.DataItem("ImageURL") %>"
align="left" hspace="10" />
<b><%# Container.DataItem("Title") %></b><br />
ISBN: <%# Container.DataItem("ISBN") %> &nbsp;
Published: <%# DataBinder.Eval(Container.DataItem, _
"PublicationDate", "{0:d}") %><br />
<%# Container.DataItem("Precis") %>
</div><br clear="all" />
</ItemTemplate>

<SeparatorTemplate>
<img src="images/redrule.gif">
</SeparatorTemplate>

<FooterTemplate>
<img src="images/redrule.gif">
<div class="rFoot">
For more information visit <a href="http://www.wrox.com">http://www.wrox.com</a>
</div>
</FooterTemplate>

</ASP:Repeater><p />

<!--------------------------------------------------------------------------->

<script language="vb" runat="server">

Sub Page_Load()
Universal Knowledge Solutions s.a.l 143
'create a new empty DataTable object
Dim objTable As New DataTable("NewTable")

'define four columns (fields) within the table


objTable.Columns.Add("ISBN", System.Type.GetType("System.String"))
objTable.Columns.Add("Title", System.Type.GetType("System.String"))
objTable.Columns.Add("PublicationDate", System.Type.GetType("System.DateTime"))
objTable.Columns.Add("ImageURL", System.Type.GetType("System.String"))
objTable.Columns.Add("Precis", System.Type.GetType("System.String"))

'declare a variable to hold a DataRow object


Dim objDataRow As DataRow

'create a new DataRow object instance in this table


objDataRow = objTable.NewRow()

'and fill in the values


objDataRow("ISBN") = "0764544020"
objDataRow("Title") = "Beginning Access 2002 VBA"
objDataRow("PublicationDate") = "February 2003"
objDataRow("ImageURL") = "4020.gif"
objDataRow("Precis") = "Access 2002 is the core database application within " _
& "the Office XP suite. This book focuses on the programming language that " _
& "underlies Access 2002 and all the other office products."
objTable.Rows.Add(objDataRow)

objDataRow = objTable.NewRow()
objDataRow("ISBN") = "0764543636"
objDataRow("Title") = "Beginning Active Server Pages 3.0"
objDataRow("PublicationDate") = "July 2000"
objDataRow("ImageURL") = "3636.gif"
objDataRow("Precis") = "This book is for beginners who have no previous experience " _
& "of ASP, C#, XML, object-oriented programming, or the .NET Framework. A little " _
& "knowledge of HTML is useful, but by no means essential as all the concepts that " _
& "you need in order to create dynamic ASP.NET web sites are presented and explained in full."
objTable.Rows.Add(objDataRow)

objDataRow = objTable.NewRow()
objDataRow("ISBN") = "0764543695"
objDataRow("Title") = "Beginning ASP.NET 1.0 with Visual Basic.NET"
objDataRow("PublicationDate") = "February 2003"
objDataRow("ImageURL") = "3695.gif"
objDataRow("Precis") = "This book is for beginners who have no previous experience of " _
& "ASP, VB, XML, object-oriented programming, or the .NET Framework. All the concepts " _
& "you need in order to create dynamic ASP.NET web sites are presented and explained in full."
objTable.Rows.Add(objDataRow)

objDataRow = objTable.NewRow()
objDataRow("ISBN") = "0764543962"
objDataRow("Title") = "Professional ASP.NET 1.0, Special Edition"
Universal Knowledge Solutions s.a.l 144
objDataRow("PublicationDate") = "February 2002"
objDataRow("ImageURL") = "3962.gif"
objDataRow("Precis") = "This book is for people that have a solid understanding of ASP " _
& "and are familiar with VB or C-based syntax. It will show you how to develop sophisticated " _
& "ASP.NET applications using the .NET Framework with its comprehensive and in-depth guide " _
& "to this exciting new technology."
objTable.Rows.Add(objDataRow)

'assign the DataTable's DefaultView object to the Repeater control


MyRepeater.DataSource = objTable.DefaultView
MyRepeater.DataBind() 'and bind (display) the data

End Sub

</script>

<!--------------------------------------------------------------------------->
</body>
</html>

Universal Knowledge Solutions s.a.l 145


7# <4  

: 
 5  K$2 $ % 4

:   
.K$   ,
  $

:!"
6  *6 !6 6 ] (6,8 6,
 /0. ! 9  .  W  !  2  ,8 $ 5, % 4 X#$ 
.  5   K$> (,8 9  + $ 1 ASP.NET

:  # $%&
:(,8 *# 0. !  9 
$ % 4  # •

ASP.NET ! $  T2 •
ASP.NET !   K$2 •

Universal Knowledge Solutions s.a.l 146


ASP.NET 
52   ;

*8# ,$  *; 2    % $ *;  T2 2  @ (,8 X$  G $ % 4 9_ F
.  1 

.  ? 0. (4 *, *W  2 ASP.NET 


(Session)  $ L
(Application)   $ L
(Cache)  ,  ,$  $ L
+ 5&$ L

*8# ,$  *; 2    % $ *;  T2 2  @ (,8 X$  G $ % 4 9_ F
.  1 
.  ? 0. (4 *, *W  2 ASP.NET 
I0 Session  ?   $ (,8 A- +$  :(Session)  $ L
5  + .$  ( @ 20 +  %8)   %$ % 5  (,8 A- '
. H    ? 0. 5  8 <    Session  T
.  X[ @ !  ;8- 5  1  2 04 Session  ?  + *7 *  (,8
  5   $; !     *; 1@ 1 *8#    0[ .  
. 0   0$
 ? *;   ,8 A-   $ +$  :(Application)   $ L
1 
 $ 5  /0. + .     5  (,8 X#$ ' I0 Application
.(...  5   5$#) 
*8 + .Cache  ?   ,$  $ +$  :(Cache)  ,  ,$  $ L
 I2  C 4 * + I2 3 = C+ ! Application  ?, C= Cache  ?
 T * .G  2 , @ *7 *  (, . 4    ? 0  2 &4 .    
2 1  .8 ‘    * ?= A 8 XML 9,  ASP.NET 5$# 1 
 
! .5   XML 9, (,8  ? 0  < =J G= Cache  ?   ? 0. 
.5 ? C ,8 5 I0   $; A?[  30 ASP.net $ 5  9, ? *$
Universal Knowledge Solutions s.a.l 147
$2  + Cache  Application  ?  (4 - :+ 5&$ L
'  + K $ .+ 5&$ !. ASP.NET ! C
   T W    ! 5; 
I0 9 f 8 +   5 ? /0.  % $  A=4   .8 + 5 ? 8
./J=4 B

 ?  %W 7+2 + 5&$  !   8 5 ? /0. (4 * +
.Application

 @ E& " 4

.ASP !  & < ASP.NET ! Session  ? Application  ?  +

.*+=  I2 , \#+ 9 $ ,  $  @ 4 !#+ 04

' Set an Application value


Application("SomeValue") = "my value"
' Read an Application value
Dim someString As String
someString = Application("SomeValue")

' Set a Cache value


Cache("SomeValue") = "my value"
' Read a Cache value
Dim someString As String
someString = Cache("SomeValue")

' Set a Session Cache value


SessionCache("SomeValue") = "my value"
' Read a session value
Dim someString As String
someString = session ("SomeValue")

.* # $  T2   T *+ (,8  'W = ! 9 

.ASP !  & < ASP.NET ! Session  ? Application  ?  +

.*+=  I2 , \#+ 9 $ ,  $  @ 4 !#+ 04

Universal Knowledge Solutions s.a.l 148


.* # $  T2   T *+ (,8  'W = ! 9 

Session @ A /  @ E& " 4

 5,$  .ASP !   8 $  ASP.NET ! Session  ?  F
:!.      58 ! *+=  8
 Session  ?  
   7+2 
 8 % 8 !. (farm –  5  8
) (   8 •
   !  , /0. 5+ .%  *+ ! 9,   , * $ I
2 + K $
.  (,8 < ,$  ,
 5, +  ;
< ,  $>  ! 
.Session  T> 5,  $  3 =, 5 84  2 +  % 
  ! 2
(4 * 1   0. + 04 H  (4  , * $  & $ /0. !
.,
 5,
.  *@  5++ 8 2 * #  ($ Session  ?  8 •

: Session @ A " 4


)


1 *  .ASP.NET    *+ 5   < Session  ? +
.\#/ @ %8@ (,8 5   I
 HashTable  ?+ Session  ?

:Session @ E   = F = 4;

: VB.NET ! !   Session  T (4  T 2  @ 4 +


Session(“[string key]”)=Object

:C# !  = ?  
Session [ “[string key]” ]=Object;

 T !  “Hello world” 9 $ , ,7   %  2 04 *7 *  (,8
:+ !#+ “SimpleSession” \#  Session
Dim sessionValue As String
sessionValue = Session("SimpleSession")
Universal Knowledge Solutions s.a.l 149
:C# ! 
string sessionValue;
sessionValue = Session["SimpleSession"];

 $   * $ (4 P$  T> 9 $ *; 8 #, d  2
,
  T  C  /A=[ @  9 %  2 04 *7 *  (, . ,
: + PurchaseOrder  ? + 
Dim po As PurchaseOrder
po = CType(Session("po"), PurchaseOrder)

: + C#  2
PurchaseOrder po;
po = (PurchaseOrder) Session["po"];

.PurchaseOrder 9 $  (4 I @ * $  , @ 2 X$;

Session  ? W 

: ? 0.   * !    $ W  8


 Session  ?  •

 * Session  T +  $ false 2 True     IsCookieless  •


.    2 5++
.5++   * 2 ( False !. *,  W,   +

! * Session  T + $ False 2 True   B$4   IsReadOnly  •


!    ?   ' 2   & ! 5&$ ! % #   /0. . %A   
.Session  ?
! %$ 5  (,8 *  %A  '  2 I2 False !.  /0   W,   +
.Session  ?

5&$&  8
 3. .Session  ? 5,   $ ! Mode  •
.inproc  off stateServer sqlserver  +  ,

Universal Knowledge Solutions s.a.l 150


Application @ A " 4
:
   ;

 ? *+= %$ (,8  *+ 8 5,   Session  ? +
. , + = 5,  + Application
.  *+  + =  A=[ T  $ ! < <
 # 3 =  0. +

5 W7 *+= (,8 5   04    s+ HashTable  ? Application  T 
. @\\#

  * ASP.NET A
4 8 ,# %  5    # Application  ? 8 &
1 
* C8;@4 %84 2 B 2 %  A
- 0.  %84  ,8 5 0[ A
-  5 
.C   5 

 +2 8  (,8 ,$ +  ;&    8  ! + $ (,8 .   +
.U
&  ,8 - H A
4 A8  U 2 A
- #  5, U
 >

:Application @ A  () 4   4


1  3,  = Application  ? *   (4 *,  ?  
: $ A7 Session  ?
   &  % W   Application  ? (4 * + C2 8 •
1  L5  ?    %  *+ !L  & C2 ! 0. . ? 0. (,8 57 $ 
 ?  X$ $ .K $  ,8 A 4 $ H   2  I>  4 *
.5 , *#@4    30 * 0. +  H Application

Universal Knowledge Solutions s.a.l 151


Application @ A 

  F =

:!,   = ?   *;  Application  ? 5  %A @ +

:VB.NET !
Application (“HitCounter”)=1

:*+=  C# 
Application[“HitCounter”]=10;

:*+=  ?   2 !#+ Application  T !    %A @  2 04 C= *+=

:VB.NET !
Dim hitCount as integer
hitCount=Application(“HitCounter”)

:C# !
Int HitCount= Application[“HitCounter];

 ,8 I2 A
4  B > 5   1  2  ;  *#@-    2
.!$   2  *@   ? 0. $ $ 5 , $ 2 K $

(,8 $ X#$ Application  ?  + !8  + ? + = 5  5+ 04
.!,72 T ,T>

Application @ A 



  F =

:Application  ? (,8 *#@>     I0 ! *7 X$;

Universal Knowledge Solutions s.a.l 152


:VB.NET !
Public Sub Application_OnStart()
Application("HitCount") = 0
End Sub
Public Sub Application_OnBeginRequest()
Application.Lock()
Application("HitCounter") = Application("HitCounter") + 1
Application.UnLock()
End Sub

: C# !
public void Application_OnStart() {
Application["HitCounter"] = 0;
}
public void Application_OnBeginRequest(){
Application.Lock();
int tmpInt = (int)Application["HitCounter"];
Application["HitCounter"] = tmpInt + 1;
Application.UnLock();
}

8  Application  ?  Lock()   A8  !


   ! @
.5@ # ! HITCounter 5  K $ H A
4 I2 $
;4 I
K $ . +0 + 5  1 
* C %84 2 ASP.NET A
- 9 4 8
! K$ 0. V  + .C %84 2   9 4 8 Application_OnEnd K$
.5  %8@ 2 9,  5 , X#$  ,8 A
[ T  *$

8 Application  ? $ < W, ASP.NET  Unlock   A8 8 *$ !
. G  X *$ ! 2  ,  ,   A  2  ,  ,  A &

Cache @ A –     ;

9, %A @ ! *$ !. + .% 7+    $ +       
.  % +0  0. XML 9, *7  ?  .8 I
04 .5
 *  I$ XML

j5
 *  *7 XML 9, ? *$ ! *$ I0 

Universal Knowledge Solutions s.a.l 153


I
   * ?= %8[ ? 3  Application  ?    5&$ X !
.5, K $
(4 4 Application  ?    ' ! Cache  ?   A   9  +
4   J ' K $ / ?  8 cache  ?  8  *7 B 2  
.!
    Cache  ? (4  
 

(4 4 System.Web.Cache A> A  


 Cache 9 Cache  ? C=
.Session  Application  T> *$+ \#\ @ %8@ (,8 HashTable  ?+ * C+

:    Cache  ? 8


Cache  T ' # + 2 + B 2  T2 (,8 .8 (,8 A 5 ,  $; A  L
 ?  ,8  !  T> 2 5   I2 (,8 ? I2 8 . 5@ f   5#, B 2
.Cache  ? 5    4  $ T 5  8  Cache
 ? + .application  ? $ !  I0, C= *+=  , /0.  :*#@> % 4 L
Lock() & < @  ,
&   , *#@2 % 4 Cache 9 3, Application
% 4 (4 P$ *  2 8&  0> 1 Cache  ? 5  (,8 *  8 Unlock() 
.Application  ? 1 , + Cache  ? !   Td  *
 R  C  (,8    % +0 (,8 ? Cache  ? 9=+ 8 :  % 4 L
.&
< 2 /
  $  ,8
 8 I2 , *@ 0 .< *@> 
 8 4 8 !
   * ?= \  +4 Cache  ?  :1
  A8& L
. ? 0.

Cache @ A 52 # > ;

:  P -   Cache  ? 8

 Session  T> 1   #  +   G   /0. :   
:*+=  ?  +  @\\# P>  Application

:VB.NET !
Universal Knowledge Solutions s.a.l 154
Dim productDataSet As New DataSet()
' Populate DataSet
Cache("products") = productDataSet

:C# !
DataSet productDataSet = new DataSet();
// Populate DataSet
Cache["products"] = productDataSet;

8& 5@;+  5@;8  $   /0. ' .Insert()    : $   
:?  ! +

:VB.NET !
Dim productDataSet As New DataSet()
' Populate DataSet
Cache.Insert("products", productDataSet, Nothing)

:C# !
DataSet productDataSet = new DataSet();
// Populate DataSet
Cache.Insert("products", productDataSet, null)

.Insert() * $    ,T> (,8  Cache  ?  8

  0 5


 . F( ;

 8  @;8 A=4  + C2 04 %  T !  H  8& (,8 !  $; A  
:*7 .   %$ % # 9, Cache  ?

<%@ Import Namespace="System.Xml" %>


<%@ Import Namespace="System.Xml.Xsl" %>
<Script runat="server">
Public Sub Page_Load(sender As Object, e As EventArgs)
Dim dom As XmlDocument
Dim xsl As New XslTransform()
' Do we have the Wrox Pro ASP.NET 2nd Ed book in the Cache?
If (IsNothing(Cache("1861007035.xml"))) Then
CacheStatus.Text = "Item not present, updating the Cache..."
UpdateCache("1861007035.xml")
Universal Knowledge Solutions s.a.l 155
Else
CacheStatus.Text = "Retrieving from Cache"
End If
' Load the transform
xsl.Load(Server.MapPath("book.xsl"))
dom = CType(Cache("1861007035.xml"), XmlDocument)
BookDisplay.Document = dom
BookDisplay.Transform = xsl
End Sub

Public Sub UpdateCache(strItem As String)


Dim strPath As String
Dim dom As New XmlDocument()
' Determine the file path of the file to monitor
strPath = Server.MapPath(strItem)
' Load the file into an Xml Dom
dom.Load(strPath)
' Create a CacheDependency on the file
Dim dependency as New CacheDependency(strPath)
' Cache the XML document
Cache.Insert(strItem, dom, dependency)
End Sub
</Script>
Status: <asp:label id="CacheStatus" runat=server/>
<br>
<asp:xml id="BookDisplay" runat=server/>

B > 5 , ] *   ? , Cache  ? , 5 ,  *7 ! X
 +G  9 + X$; . ]   U 0   ,
 # + XML 6 ,
 XML  7 ?  (4 C, $  C  9 +  Cache  ?   

 9,, *$ XML  7  T - UpdateCache  W
-  + 9 + 2 .CType
 G  
CacheDpendency  T  $  Insert()  ,  Cache  T (4  

.Cache  T 9,  @;8

 8  @;8 A=4  + C2 04 %  T !  H  8& (,8 !  $; A  
 ?Cache . ? #  H \# 2    %$ X$ 9,

8

0 + .XML 9,  T (,8 Cache  ? A$ @   # +  $ = ! *7 '
. ? 0.  H 8 *  8 Cache  ?  7+2 2 8 4  2 

Universal Knowledge Solutions s.a.l 156


  0. 8  ?  + .\# 2 (,8  8& (  8   0. G 
?   1  *7 *  (, .9, 2 (,8  8&  8  3,  =
. >  8
 *  \# 2 (,8  8& 8 K $  *7, !
  

<%@ Import Namespace="System.Xml" %>


<Script runat="server">
Public Sub Create(sender As Object, e As EventArgs)
' Create the Cache entry for the dependency relationship
' the value of the key doesn't matter
Cache("booksDependencyKey") = "Book Dependency"
' Create a string array with the key names for the
' dependencies to be created upon
Dim dependencyKey(0) As String
dependencyKey(0) = "booksDependencyKey"
' Create a CacheDependency on this key
Dim dependency as New CacheDependency(nothing, dependencyKey)
' Cache the XML document
Cache.Insert("1861007035.xml", Load("1861007035.xml"), dependency)
Status()
End Sub
Private Function Load(xmlFile As String) As XmlDocument
Dim dom As New XmlDocument()
dom.Load(Server.MapPath(xmlFile))
Return dom
End Function
Public Sub Invalidate(sender As Object, e As EventArgs)
Cache.Remove("booksDependencyKey")
Status()
End Sub
Public Sub Status()
If (IsNothing(Cache("1861007035.xml"))) Then
lblStatus1.Text = "No value..."
Else
lblStatus1.Text = "Cache entry exists..."
End If
End Sub
</Script>
<form runat=server>
<input type="submit" OnServerClick="Create"
value="Create Cache Entries" runat="server" />
<input type="submit" OnServerClick="Invalidate"
value="Invalidate Key" runat="server" />
</form>
Status for cache key: 1861007035.xml: <b><asp:label id="lblStatus1"
runat=server/></b>

Universal Knowledge Solutions s.a.l 157


 ? 5  A=- Create Cache Entries  ? (4 P$  !
   * ?= 8
.8& @; XML6 9,  Cache

.Invalidate K$ ;[  I0 Invalidate Key  + .

.$  %  BooksDependencyKey \# [ K$ 0.  

.< 2 XMl  7 Cache  ? 5  4 (4  @ %  0. 

2 (,8  84 A=4 + \# 2 (,8  8& 9, 2 (,8  8& (4 -
.   

:8
/0. K $ I
C2 ,8 5  %8@  $ *
! + 8 1 
  2 04
Cache  ?  5  /0  *7 Dataset  ? P  2 + U> ! %  5 
. @ 60  !   $; 1 $  % 

(,8 K $  X *$ ! ($ C2  1 , *+ 8 5  %8 *& > 0.  ,8  
.  8 *; 7$ +    ! 5  [ 5 

<%@ Import Namespace="System.Data" %>


<%@ Import Namespace="System.Data.SqlClient" %>
<script runat=server>
Private DSN As String
Public Sub Page_Load(sender As Object, e As EventArgs)
Dim strCacheKey As String
Dim titlesDataSet As DataSet
strCacheKey = "Titles"
If (IsNothing(Cache(strCacheKey))) Then
lblStatus.Text = "Getting data from database..."
LoadTitles(strCacheKey)
Else
lblStatus.Text = "Getting data from Cache..."
End If
titlesDataSet = CType(Cache(strCacheKey), DataSet)
TitleList.DataSource = titlesDataSet
TitleList.DataBind()
Universal Knowledge Solutions s.a.l 158
End Sub
Public Sub LoadTitles(strCacheKey As String)
Dim connection As SqlConnection
Dim command As SqlDataAdapter
Dim sqlSelect As String
Dim strDsn As String
Dim dataset As New DataSet()
sqlSelect = "Select title, pub_id, price, notes, pubdate FROM
titles"
strDsn = "server=localhost;uid=sa;pwd=;database=pubs"
connection = New SqlConnection(strDsn)
command = New SqlDataAdapter(sqlSelect, connection)
command.Fill(dataset, "Author-Titles")
Cache.Insert(strCacheKey, dataset, nothing, _
DateTime.Now.AddMinutes(60), TimeSpan.Zero)
End Sub
</script>
<font size=6>
<asp:label id="lblStatus" runat="server"/>
</font>
<P>
<ASP:DataGrid id="TitleList" HeaderStyle-BackColor="#aaaadd"
BackColor="#ccccff"
runat="server" />

:
 B&

.* 2 *8>  7+ ASP.NET !   K$2 *




.C X !
   0 # +$, %
  K$> 

:  X
:
 B& " 4 < 4
: Global.asax $ 52 59 >? " 4 /
! I
+     /0. C= .K$d !> P0 9, [  $ /0. ! 
2 Application_OnStart *7 K$> 5
 + I
 5+ K $ Asp.Net 9, Asp
.Session_OnEnd
:  Http   /
ASP.NET *@  C  *@ Http , (,8 *, *
   Http %$  
.  ASP.Net    *,$ $   5$ /0.  1 

Universal Knowledge Solutions s.a.l 159


: -.
.K$ # (,8   Http %$ Global.asax  
 3. + 2 + •
.
$ 8  7$2 [  ' +    K$ 18 ASP.NET 8 •

59 >? :
 B& A 

: ?  Global.asax !   K$2 0G

VB.NET !
Public Sub Application_OnStart(sender As Object, e As EventArgs)
End Sub

:C# ! 2
public void Application_OnStart(Object sender, EventArgs e) {
}
I0 EventArgs * (4 4 K$ ;[ @ I0  ? C @ ! * $
.K$ 0. 8 * # 5,   K$ ,2 I0  ?, *
 ' 

:5; A  $    ?   +


Public Sub Application_OnStart()
End Sub

:C# !
public void Application_OnStart() {
}
,# ?   *# 30 Sender 2 EventArgs (4 *  ?  ! + &
.*2 +$  +  >

: 2 #  (4   K$2 9  +

Universal Knowledge Solutions s.a.l 160


M , *+ 8  @;4  K$2 L
. G K$ 8  @;4  ! K$> *7  = $ 8  @;4    = K$2 L

59 >? :
 B& A 

:  
4 B9
  (4 C
  , *+ A72  @;4  ! K$>  G ,,    K$2 9_ F
: ,      K$2 *7 ASP.NET

 C
  , *+ 1 K$ 0. ;4 I
: Application_OnBeginRequest K$ •
I0 ASP  ! Application_OnStart 9G K$ 8 K$ 0. 9, .ASP.NET *@
.  * ?= 8 %$ %  C@;4 
, V I2 + 2 *@ 2   2 $# I2 *@ !
   0 # K$ 0.  +
. , I2 (,8 * A  HTTP

' 8 K$ 0. ;4  : Application_OnAuthenticateRequest K$ •


1  K $  $ X A  ,8 K$ 0. * a  R . ,  $, %.
ASP.NET
.& 2 &
<  , + 04   $ I0 !
   0 # , $

K$  = %  K$ 0. * : Application_OnAuthorizationRequest K$ •


.  (,8 5 $ /A84   <.
, ' 8 K$ 0. ;4 I
K $ $
.5,  5 $ $ 
   0 # A=4  K$ 0. +S R

5$#  5 H ASP.NET 3, : Application_OnResolveRequestCache K$ •


B 2 5,   %  $# 0 # I
2 + , *+ $# 0 # * 9 .  5

Universal Knowledge Solutions s.a.l 161


.
  +  
.& 2 Z  C    , +  $ %.
ASP.NET ' 8 K$0. ,

59 >? :
 B& A 

:Application_OnAcquireRequestState K$ •
2 ASP.NET A
4 *  ,
 5  !, %.
ASP.NET ' 8 K$ 0. ;4 
.SQLServer  2 C
 
 ? 30  @ * .G + ;
< 7 XMLSession  ?+  Session  T   @ 04
.K$ 0. 
.  ;
< .J XmlSession  ? +    2 $#, ,  , 8

:Application_OnPreRequestHandlerExecute K$ •
V . V 0. + 5&$ X ! . ,   V A8 *@ K$ 0. ;4 
.Page
. , HTTP V , Application_OnPreRequestHandlerExecute K$ ;4 
. , 
  A &  ! K$ ;4 

 A &  K$ 0. ;4  : Application_OnPostRequestHandlerExecute K$ •


.  (4   4 I
5  Response  ? B + ,$  /0. ! . , 


K $ ,
 5  $ K$ 0.  Application_OnReleaseRequestState K$ •
.,
 5, K $ + & K$ 0. ;4  ., 8  5,

ASP.NET  8 K$ 0. ;4  Application_On_UpdateRequestCache K$ •


. !$ , W  % +0 P  K $

+$  '  C@;4   I0 > K$ . 0. :Application_OnEndRequest K$ •
.
& 1 HTTP 5   * 4 *@   


Universal Knowledge Solutions s.a.l 162


59 >? :
 B& A 

:   K$d !  !,  

Universal Knowledge Solutions s.a.l 163


% +0 K$> 2 .8 ASP.NET A
- (4 C , , !, IIS  /;82  . +
.  %  Application_OnBeginRequest  <A ;& <
.Application_OnPreRequestHandlerExecute ;4 I
HTTP V A8  2 *@
K$ , 0 #  HTTP V 0 # A  
.Application_OnPostRequestHandlerExecute
.Application_OnEndRequest K$ ;4  IIS (4 
&  , *@ < 2

59 >? :
 B& A 
' 8 ,  + , *+ 1 + ! K$> 8
 (4    H 7$ 3.
.  (4   4   %.
5 

$ &4   (4 5  * [ 2   2 !  Buffer !W, *+= ASP.NET *^#
.%.
5  /0. '

:Application_OnEndRequest    7$ , Buffering * # 8


 (4 HTTP 5   * 4 *@ Application_OnPreSendRequestHeaders K$ •
. , $
*   (4 
& * 4 *@ Application_OnPreSendRequestContent K$ •
. ,

:

" 7 B9

*+ 1 + ! K$> , *>  :ASP.NET !   K$> #  
  +0
.  = K$> ] !? ,

. , 
 *; X & 2 X 2 + ! K$>  G   = K$> 9_ F
 X 8 2 Application_OnStrat K$ , (> % ,   * ?= 8 *7 *  (,
. Application_ErrorO K$ ,   ! G

Universal Knowledge Solutions s.a.l 164


+ . (> % ,   * ?=  8 K$ 0. , :Application_OnStart K$ •

 K$ 0.  + . , *+ 1 , R & Application_OnBeginRequest K$
.5,    
.5   (,8 *$ 5  %8@ 1 *  G K$ 0.  :*7

K$, * . < 2 %$ %  K$ 0. X :Application_OnEnd K$ •


K$+ K$ 0.  + .  * ?= 9 4  8 C@;4   Application_OnStart
X + 1@ ! . Z  5  c # 5  %8@ 1 *& ;T4 5 ,8  .9 X
&4  , %
$ % +0 $ 3, 9 X  ,  CLR +    T  5 ,
.#G  , 3, A
4 <W *#R C2
7 :
 B&

  !   ,


2 8 K$ 0. ;4  Session_OnStart K$ •
 ?  @ 4  ,+   !
   0 #   0.  + .ASP.NET
.Session

,
A  8 (,
A K$ *) K$ 0. ;4  :Session_OnEnd K$ •
  .  *
 ,
 5  ! *
, 2 ,
 5, X#$ K$ 0.  + .
. 5  %8@  

0.  .   G  X 8 K$ 0. ;4  :Application_Error K$ •
8 5; # X    * 4 !  
 A>  ! 8 C>  .>  = K$
.G

CLR !   * ?= 9 4  8 K$ 0. ;4  :Application_OnDisposed K$ •


.< , & * ,@ K$ 0. + .  % +0 $ 

  (    *+ !  ,+  


 C2 ASP.NET ! K$ 18 
 ! &
. , <W8 >

8&

Universal Knowledge Solutions s.a.l 165


ASP.NET ! 5  K$2 * ! ,7>  8
   !,  

: < ) 0;  ? 2; 8



& * 4 *@ <  ,    ! C@;4  Application_OnEndRequest K$ 2  +0
     ! 5$# 1 
(4 * 0 4  5 2   2  # .  (4
:*+=  .8 Global.asax 9, + 2 + .ASP.NET

<Script runat="server">
Public Sub Application_OnEndRequest(sender As Object, e As
EventArgs)
Response.Write("<hr size=1>")
Response.Write("<font face=arial size=2>This page was " _
& "served by ASP.NET</font>")
End Sub
</Script>
“This page was …” %   X- Response.write   /;82 *7 !

:" 4
" 
  8
    2  0 . , *    $  #   1@    
.     8

 8
 *+   Bronze Silver Gold !. 58
 (4 $    2 04 ;
< 7
. @ 58
, $ T   (4 * A&J.

 Application_OnAquireRequest K$  8 8 $  A   1 


:*7 .C  5  $ , *+    $
<%@ Import Namespace="System.Xml" %>
<Script runat="server">
Public Sub Application_OnAcquireRequestState( _
sender As Object, e As EventArgs)
Dim dom As New XmlDocument()
Dim customerType As String
' Grab the customerType from the QueryString
customerType = Request.QueryString("customerType")
' Check for values
If (IsNothing(customerType)) Then
customerType = "Bronze"
End If
' Load the appropriate XML file

Universal Knowledge Solutions s.a.l 166


Select Case customerType
Case "Gold"
dom.Load(Server.MapPath("Gold.xml"))
Case "Silver"
dom.Load(Server.MapPath("Silver.xml"))
Case Else
dom.Load(Server.MapPath("Bronze.xml"))
End Select
Session("WelcomeMsg") = _
dom.SelectSingleNode("/customer/welcome").InnerText
End Sub
</Script>


 F "& )#

.  5  A CLR  + CLR * Asp.Net 5+ 

5 +> /0. 
 + .CLR !  >   $2 Try/catch   5A7& 
 
.*,  7+ I$ 
   A  1 &   /0. .  !  

/0. 9,? 2 + + .  %A  5  %8 *&  <
  < + @ *7 *  (,
G 0. 
 *&  + 8 *$ ! + .8 try/catch ,+ ! !
  
. % 
 * ?= G+ /  X4   j try/catch ,+ P  A7& X 04 *$  I0  +
.C    + I0 * 8 C+ 8 G 8 * #

  ! A& 1 


& Page_Error K$ 8 ASP.NET 5$#  +
. 


:30 ! 8 Application_Error [   B (,8 A> 1 


  @ 04 2
<%@ Import Namespace="System.Diagnostics" %>
Universal Knowledge Solutions s.a.l 167
<script language="VB" runat=server>
Public Sub Application_Error(Sender as Object, E as EventArgs)
Dim LogName As String = "Web_Errors"
Dim Message As String
Message = "Url: " & Request.Path
Message = Message + " Error: " & Server.GetLastError.ToString
' Create event log if it doesn't exist
If (Not EventLog.SourceExists(LogName)) Then
EventLog.CreateEventSource(LogName, LogName)
End if
' Fire off to event log
Dim Log as New EventLog
Log.Source = LogName
Log.WriteEntry(Message, EventLogEntryType.Error)
End Sub
</script>

0. ! 9#   > System.Diagnostics A> A   /;82 *7 ! @
.K$> *
 + A#
.5&$  8
 A=- Application_OnError K$  . @
./A=4 (,8 * /
  0[ .SourceExist()    K$d *
 
  +G @ 7
P - WriteEntry()    @ Log  EventLog 9  * 7 A=[ . @
.Windows K$2 *
  
.Web_Errord (  K$> *
  C,
     ! G I2  X *$ !

9, ASP ! <  60 , @  ,8 A> 2 10  + G . X$;   &
.ASP.NET

Universal Knowledge Solutions s.a.l 168


7 B8 S 7 58 S 7 1 

: 
.NET ! 5  % 4

:   
.   % =G #  T  2 *

:!"
5+ A 5    + 8 1 * 5  % [ ' ! 5    @ 8
 .NET   
.XML W7 *7 W7 2  W;8 5  8 ,7  /0.

:  # $%&
:(,8 *# 0. !  9 
   # + (,8 NET. ! 5  % 4  T2 •

Universal Knowledge Solutions s.a.l 169


ASP.NET 52 
  ;

.  .ASP.NET ! 5  % [ , 1   ,
 ,
 /0. ! !?
. 
 B 2 5  5#, !  5  (4 * 5 ,8 5  % 4 

.
 *"
5,   - ! !

 5  (4  * 5  ( ! 9#  8
 NET. *8 4 
.NET 1 ; < 

:( ;  


 *"
! 5  % 4 5  + 5  8@ *7  W; 5   5  % 4  # 
.    5  XML 5#, 1 * *& :  %  B 2 5 +4  .NET

.txt 5#, ! *$ !. + $ *


 *  9, (,8   %8 5  8@ 5+ <  

Universal Knowledge Solutions s.a.l 170


5  (4 * 5  2 5  8@ V  *@  *
(4 5#, %A @ I
 5+ 04
P  .   #, *
 5;
   B 2 5#, ! %
 8@ F 5+
5  *
, !+   * 1 *2      W; 5  8@ 5 X 5  /0.
. 5  %8@ . !>  + ! *$ I2 (,8 .5 ,   7+2 *

: * C
 0;  
8 &  *8> X ! 5  *8 5 H 5,    5 ? % > 5 !
W7 ! +&   5  8 5  5$2  +   W; 5  %8@  #
.< 2 5  8@  B 2 W +2 +

.NET 52 
  ;

  0 . 8 ,+ ! 8 % 


 W  1  5  (4 *, % 
5  

.*
 0. ! < , .NET C 

% 4  T2 1 

 9 + B  .NET! 5  % 4 9# 1 
8 8 $ A8[ 2
.NET   ! ,+  
  W  1 5 

:F49 F2
ado.net , %8 ,  system.data A> A (,8  W; 5  % 4 9# 1 
(F
:! *
 ! %
 A> 5A (,8
$ F49 F2
(4 *,   >  T> 1 
 System.data
/0.  . W; 5  8@ ! 5  
Universal Knowledge Solutions s.a.l 171
.DataRelation  DataTable  Dataset : T>
5    8 ,  T> /0.  *+ +
.  0    * !  
B >  T>    > 9# I$ System.data.com
mon
 OleDb A> A    T> 
0. A> A    & 8 %  .SqlClient
.  !
5   1 *; F !  T> I$ System.data.OleD
b
 OleDbConnection *7 Ole-Db  
W    T> /0. K  .OleDbCommand
+ = 9# 
 1 *;   + !  T> I$ System.data.SqlCl
ient
SQL   
 5     8 5 
5   [ *2 A2  K $ . Server
 T> K  .OLE_DB *  ,  
9#  SQLCommand  SQLConnection *7
.K$>   W OleDb 6+ + =
8@ ! 5  2 & ; 9# I$
   3, 8 #,SQLServer *7  W; 5 
 SqlMoney. SqlDateTime  TG+ .NET ! System.Data.SqlT
.SqlBinary ype
*,  X$, *+= A>  T> /0.  $
.5  2  * $ A2

  0 . 8 ,+ ! 8 % 


 W  1  5  (4 *, % 
5  

.*
 0. ! < , .NET C 

% 4  T2 1 

 9 + B  .NET! 5  % 4 9# 1 
8 8 $ A8[ 2
.NET   ! ,+  
  W  1 5 
Universal Knowledge Solutions s.a.l 172
.NET 52 
  ;

&
<  XML 5#, 1 *,   + 9# (,8  $ A> 5A  ,, < 2 3.
.System.Xml (,8   A> /0. +  W; 5  8@  

 %A @ A=- ;  >  T> I$


5  $ XML W7 
 +  
.W3C
System.Xml
 ,, (4 - XmlDocument I$
 7 !   #, U2 *7 !  T>
.XML

   A=4 8 J  T> I$
System.Xml.Schema
.XML  7 *+ . ! %$  *+ 
  + !  T>  8
 I$
System.Xml.Sirializa
*7 #, B 2 5  (4 XML  7 * $
tion
.;
< 7 += 8 *, SOAP
 %A  5 ,8   ; 9# I$
!  T  XML W7 8 ; +
XpathDocument *7  T2  .XPath (,8 System.Xml.Xpath
5  *7 !  T> XpathNavigator 
.XPath
(4 XML 9, * $  , ;  T> I$
 ? + .XSLT  XSL  B 2 5  System.Xml.Xsl
XslTransform . C  !>


  < # *. F49 F2  4

A> 5A   2 .NET * 4 9# +   T2  ! 5$#,  &

Universal Knowledge Solutions s.a.l 173


.< W, 5A# /0.  7+   I
. 8 * 7 A=4   !  T- (,8  $
/   ,8
0 < W, .   ! 5A# 3,,    5  % 4 A2 A +
:!
   ! $  % 

:System.Data F49 F2  4


I
) 2 *@> (,8 System.Data A> A     &  W; 5  8@ (4 *,
*&  !   (,8 <8 System.Data.SqlClient 2 System.Data.OleDb 
:?  30 5   1  
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %>
2
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
Using  C# ! Imports  VB.NET ! +

 ?  8 A=4 $+ B 2 A2 5A  &     5&$ 3.
+ .System.Data.Common A> A    ,8
 K $ DataTableMapping
! U>  5  2    8 System.Data.SqlType    ,8

SqlServer C

:System.Xml F49 F2  4


8 X T <T + .Net 5+ 9# !  T>  XML 5  (4 *,
. System.Xml !> A> A  
 T A=4   8 System.Xml.Xpath A> A   (4  *$ *+ (,8
.XpathDocument
8 XslTransform  ?  8 System.Xml.Xsl A> A  & < 2 
.XML W7 (,8  
 * $ 5 ,8 A
4
5) Schemas 6 1 * 8 System.Xml.Schema A2 A   , +
.(*+ 
  (4   P$ ; XmlValidatingReader *7  T>  2
.System.Xml.Schema

Universal Knowledge Solutions s.a.l 174


:*+=  G  (,8 *$ ; A> 5A  I2     *$ !

449 ADO.NET @ E&

.  $ ! W  T (,8 LADO   5 !L 5  (4   , *   58
:! ,   5+ Recordset
OLE-DB 8 ODBC 2 OLE-DB   5  %8 *  G •
G= *& (,8 2 0 # •
 & RecordSet  T  5   •
Connection  T   8 2 Command  ?   2    0  + •
% =
 ?    W
4 2 SQL % 8 0 #  + 5  *  2 P - •
Recordset  ?   Command  ? Connection

Universal Knowledge Solutions s.a.l 175


 B 2 8
  +    # (,8 .NET ! 5  (4 * 
  A> ! 9; 1 < , I 0
*+= #,  +  =  T> /0.  @ . T>
DataReader *> 2  T (,8 .NET ! 5  (4 *  T2  04 . +2
.C  Recordset  ? + I0 *  ? ;+ 0# . DataSet . !7

%A , $ /


 5  (4 * ! 8 DataReader  ? 2 ! ! W   # +
 #  9#  8
  7+2 1 *,  H Dataset  ?  $ ! .
%   W,  2 5    %
 5   DataSet  T A=4 + K $ 5 
.!
    ] , 9 % =

 ,8 ,8 A72 5 ,  ,>   *$ 5, (,8 DataSet  ?  *
*+ I$
.$& 5@ ! 5   (4 5  (,8 5;  I2 * 4 + K $

. ' # 8 %8> G+ *


 I$ 9 5, I$ DataSet  ? I$
W  !   @ %  * (,8 %  . DataSet  ? !  +  2 <W +0 2

. , T

5  (,8  $ XML  7  5, * $ 1   C $ (,8 DataSet  ? X$
.' $   ,+ 

449 ADO.NET @ E&


:Connection @ E&
0.  .C  = W I$  ADO 1   ? % + %   ? 0. C=
. 5   Command  T *  ?
OLE_DB  1 OleDbConnection  ?  R •
SQLServer 5  8@ % 4 X 1 TDS (  SqlConnection  ?  •
 T ' 2 5   (,8 SQL 5 , 0 # Connection  ? < +  +
Universal Knowledge Solutions s.a.l 176
 *&  T2 J *$> *+ (,8 . + T 0  ASP.NET ! 2 .RecordSet
.  5   (,8 0 #  @ + ! 5;@ (4 *

:  @ E9 449 : 
SqlConnection  OleDbConnect *& ! T  *+ ,  T> .2 

$  
*7  $ 58-  5   (4 * '#  Open
ConnectionString , *& 5, $ !
.C
.5   1 !$ *& ;T[  Close
 T   5   1 ,@ 2 Transaction BeginTransac
tion
.,@ A?4 2 - C + I0
:8
' SQL Server Provider Sample
Dim connStr As String = "data source=(local);” & _
“initial catalog=Northwind;user id=sa"
Dim cnn As New SqlConnection(connStr)
cnn.Open()
' Use the connection in here…
If cnn.State = ConnectionState.Open Then
cnn.Close()
End If

449 ADO.NET @ E&


: 9 @ E&
 T * F W # 3, ADO ! Command  ; 7  T> /0. C=
DataAdapter  T DataReader  T 1 Connection
OLE-DB  1 OleDCommand  ?  •
SQLServer !  
 5  5 1 SqlCommand  ?  •
 .5   (,8  5 W
4 2 SQL 5 8 0 # Command  ? ' •
 ?+ 2 DataReader  ?+ H  T  4 *,  K $) 9# 8
 %84 0.
8
   & ! 5;& % 7G  8 %84 2 % $  @ %84 2 (DataAdapter
9#

Universal Knowledge Solutions s.a.l 177


: >  TG    W   

9  
 !   > 0 # CommandText
 9  *& Connection  
ExecuteNonQ
 ,+) 9# I2   & ;Update  Delete 2
uery
Insert ! 9# 8 8  ' $ @ %84 I
 .(
.;& 0  5 7G
 ! 9  > 0 # CommandText 
 ! 9  *&Connection   /0.   .
ExecuteReader
 Treader 5  %8@ ! 9# 8
 1 *
.9# (,8 *$ ' *+=
 ! 9  > 0 # CommandText 
 ! $ *&Connection !. % $  @   .
.  ! 9# 8
  *>   *>  ExecuteScalar
  /0. .% B >   1 
*.4   ;&
. % $  @ %84 , + 8   

:*7
' OLE DB Provider Sample
Dim strSQL As String = "SELECT * FROM customer”
Dim cmd As New OleDbCommand(strSQL ,cnn)

' SQL Server Provider Sample


Dim strSQL As String = "SELECT * FROM customers”
Dim cmd As New SqlCommand(strSQL ,cnn)

449 ADO.NET @ E&

:DataAdapter @ E&

Universal Knowledge Solutions s.a.l 178


DataSet  ? 7+2 2 Command  T *  < 
<8  T>  U 0. 
OLE-DB  1  OleDbDataAdapter  ? •
MS SQl Server   
 5  5 1  SqlDataAdapter  ? •
:5   ! 5  1 *,  > 9 a F W  2  T> /0. 
DeleteCommand  UpdateCommand  InsertCommand  SelectCommand
3 =&  T> /0. *+ + ) Command  T (4 =J W /0.  *+ *+= K $
.( $ Connection  ?

449 ADO.NET @ E&


: DataAdapter @ E& ( 5  449 : 
 T2 1 *,    8
 SqlDataAdapter  OleDbDataAdapter  T2  *+ 
:!. 7;7   3, .2. ,8  ! DataSet

$  
> 0 # SelectCommand  ? * .G DataSet Fill
K $   < 2 + + .5    5 

Universal Knowledge Solutions s.a.l 179


 T ! *
 %  5,DataSet 5; 
3. + 04 !,> 5   ! 5  (,8 5 !
 T  *
 ! 5  9#   ! W \#
Dataset.
> SelectCommand *
  ,+    ;& FillSchema
 T ! b  *
A=[  5   DataSet 1
.  3, .$ !   1 

> A8 InsertCommand UpdateCommand  Update


DeleteCommand  ?  C0$ 2 C,   9 *+ 
DataSet 5    5  /0. K $ I
K $
 ? B$ (,8 5 ! 5;   !>
DataSet.
    /0. C=UpdateBatch  T 1 
Recordset ! ADO $ ! +ADO (,8 *   &
.*
 7+2
:*7
Dim connStr As String = "Provider=VFPOLEDB.1;Data Source=“ & _
“C:\SAMPLES\DATA\TESTDATA.DBC"

Dim strSQL As String = "SELECT * FROM Products"

Dim oda As New OleDbDataAdapter(strSQL, connStr)

Dim cmdInsert As New OleDbCommand(“INSERT INTO Products” & _


“(product_id, prod_name) VALUES (10,’car’)”)

oda.InsertCommand = cmdInsert

449 ADO.NET @ E&


:DataSet @ A
T W  ! 5   *W  W; 5  8@ 1 * 5 2 DataSet  ? 
.,
7   0. 1 , T $ ! C *  7 5     ? 0. * .G 
.
$ $ 5   (,8 5 ? 4 *& 

Universal Knowledge Solutions s.a.l 180


:!,  (ADO ! ) RecordSet  ? DataSet  ?   >  # ,
@;  5, I$  9# 8
  7+2 1 * 2 DataSet  ? + •
.%$ 9# 8
 1 *  +4 B RecordSet  ?  & $ !   
. H %  5  (4 * T * DataSet  ?  •
8
 (4 ! DataTable U   T 8 % 8 DataSet  ? ! *
*+ +
 T2  8
 DataRow  T2  8
 (,8 DataTable  T *+ I$  .Tables
.DataColumn

. *
  5@;  W,   !> \#  +    58
 < 2 3.

30 (,8 DataView  T A=-  *


*+  DefaultView  ?   < 2 
.+$    2   * 5  ! K$ 5 +4   30 *


449 ADO.NET @ E&

:DataSet  ?   >  


*, 2 *
 5 $ 1 *,   + !    8
 DataSet  ? 
 7+2 5 $ V  ,8 2 DataSet  T B$ ' 5 ,8 *7      W 5@; 1
:DataSet  T

Universal Knowledge Solutions s.a.l 181


$  
 ? !  5  1 
[ DataSet 1 
c # 30 Clear
. $ ! *
   7+2 /J=4 %84  ?   ,8 +
.  0  =J (,8 X$ T  *$ ! &4 (  $>  !
 T B$ V   /0. DataSet  T B$ 1 Merge
DataSet  T <
 H DataSet ;+  5  1 
I$
.  ?

:XML < # 


" DataSet :
 ?  30 .5   8 Xml   . .NET / I0 !W,   <  +0
.XML W7 (4  5  + %A     8
 DataSet
9  
 7 5, %A  XML *+ . 2 XML * .G ReadXml
ReadXmlSchem
 TDataSet.  a
 7 I$   $ ,  XML *+ . 2 XML I0 GetXml

 T ! 5  *7 DataSet.
GetXmlSchema
 7 + XML *+ . 2 XML 5  *7 I0 WriteXml

 T DataSet  T 2   (,8 9, (4
WriteXmlSchem
Reader/Writer

8   $  @ 8 *
 X#$&  $ ! DataTable  T2 1 DataSet  T2 
! W  5   ! 5 ? 5 7 \,   !2 , > 0.  04  , $ 2 .A=4
.  % W  ! >
:*7
Dim connStr As String = "Provider=VFPOLEDB.1;Data Source=“ & _
“C:\SAMPLES\DATA\TESTDATA.DBC"

Dim strSQL As String = "SELECT * FROM Products"


Dim oda As New OleDbDataAdapter(strSQL, connStr)
Dim ds As New DataSet()
Dim dr As DataRow

oda.Fill(ds, "ProductInfo")

Universal Knowledge Solutions s.a.l 182


For Each dr In ds.Tables("ProductInfo").Rows
lstDemo.Items.Add(dr("Prod_Name").ToString)
Next dr

' Want to bind a Windows Form grid? It's this easy:


dgdDemo.DataSource = ds.Tables("ProductInfo")

449 ADO.NET @ E&


:5  5 7 X$  # + ! +$ (,8 +2 % @ A8- W   2 DataSet  ? 

5@; *
 (,8 ,$ 5 ? 1 
5 7 [  AcceptChan
ges
 T DataSet 0 #  %  H 0 2  , $  2 0
 AcceptChanges. 
 T   /0.  DataSet ! 5 ? *+ 2  I$ GetChanges
  0 #    %  H 0 2  ? * $  0 5
AcceptChanges.
0 2  ? * $ 0 5  (,8 5;  I2 5 04   $ HasChange
s
  0 #  %  HAcceptChanges. 
 *
 !   (,8 5 ! 5;  1 
*.[ O RejectChan
ges
 TDataSet   0 #  %  H 0 2  ? * $ 0
AcceptChanges 1 (4 5,   /0.   . 
.5 ? 8  5, 1 
*  !,>

:DataTable @ A
 T *+ DataTable  ?   8 DataSet  T ! %$ *
 (4 * +
DataRowCollection  T (4 =J Rows (  3, DataTable
.DataRow  T2 8
 8 % 8 . 

:DataTable @ E9 449 : 
Universal Knowledge Solutions s.a.l 183
*
 *
*+ 1 * ' !   W  8
 DataTable  ? 
 AcceptChanges  Clear   !. <   7+2  .B$ (,8 DataSet  T
*
(,8    2 &4 DataSet  ?  8 ! 3,  !. RegectChanges
! B >    8
 3. 2 + .DataTable  ? C 4 =J I0 *
 .  $
:!. *
 5 $ 1 * '
9  
 9 (4   *4  K $.*
 ! 9 A=[  NewRow
. !
  
.   #   ! >  8
 %8[  Select

:8

<%@ Page Language="vb" %>


<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)


'declarations
Dim mycon As OleDbConnection
Dim mycmd As OleDbCommand
Dim mydap As OleDbDataAdapter
Dim mydst As DataSet

mycon = New OleDbConnection( _


"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\myDb.mdb")

mydap = New OleDbDataAdapter ( _


"select col1,col2 from myTable", _
mycon)
mydst = New DataSet()
mydap.Fill(mydst,"col2")
mygrid.DataSource = mydst.Tables("col2")
mygrid.DataBind

End Sub

</script>
<html>
<head>
<title>Using DataAdapter – in dot net</title>

Universal Knowledge Solutions s.a.l 184


</head>

<body bgcolor="#FFFFFF" text="#000000">


<asp:DataGrid id="mygrid"
Font-Name="Arial" Font-Size="10pt" BackColor="#CCCCCC"
Width="90%" Border="0" Cellpadding="5"
runat="server" AutoGenerateColumns="False">
<HeaderStyle font-bold="True" HorizontalAlign="Center"/>
<Columns>
<asp:BoundColumn DataField="col1" HeaderText="col1" />
<asp:BoundColumn DataField="col2" HeaderText="col2" />
/>
</Columns>
</asp:DataGrid>

</body>
</html>

449 ADO.NET @ E&

:DataRowCollection @ A 449 : 
Rows  . $  DataTable  T  9#  8
  +0 +  ? 0. *7
. ? 0 
A 9 
- 9# 4 2 -    8
 DataRowCollection  T 
.*
, !> \#  @ (,8 (Constructor)
9  
NewRow   /J=4   
*
 [   /0.  Add
. *
 (4 (DataTable )
*
  %$ DataRow  T2 [  Remove
*
 ! C@ *    $  [  Remove
At
9#   ! W  \#  @  # 0G   /0.  Find
.DataRow  TG+ *
 !   ,

:DataRow @ A 449 : 
0. 3, .DataRowCollection  ?  *
  C0 $ 9 *7  ? 0.
!  ; 7 C  I0 * #  ! RejectChanges  AcceptChanges    ?
Universal Knowledge Solutions s.a.l 185
1 *,     8
  ? 0.    /0. (4 4 .DataTable  ?
.*
  $ 9 ! 5 
9  
A?4 2 X#$ $   (4 9 * $  BeginEdit,
EndEdit,
. $ 1 ! 5  (,8 5 ? CancelEdit
 C4   + 90$ 9+ 9    Delete
.Update 2 AcceptChanges   0 # $ *

*
 9#  8
 %8[   /0.  GetChildsRows
.  @; 9 0   
.9 0  G $ %84   SetColumnError
GetColumnsInEr
 HasErrors W 1   /0.  K $
ror
.G +2  $ 2 I $ RowError

:8

.C@0$  7 %$  @ I$ 9 


- Find     *7 0. 

Private Sub RemoveFoundRow(ByVal table As DataTable)


Dim rowCollection As DataRowCollection = table.Rows

' Test to see if the collection contains the value.


If rowCollection.Contains(TextBox1.Text) Then
Dim foundRow As DataRow = rowCollection.Find(TextBox1.Text)
rowCollection.Remove(foundRow)
Console.WriteLine("Row Deleted")
Else
Console.WriteLine("No such row found.")
End If
End Sub

449 ADO.NET @ E&


:DataView @ A
 ?  .DataSet  T ! *
*;  DataView  T * .G + <  +0 +
 ?  /A=4 + .*
! 9#  8
 2 *
1 * DataView
  W
8
    I0 DataTable  ? *;  2 *
  DefaultView
.*
 ! 9#
Universal Knowledge Solutions s.a.l 186
:DataView @ A 4 C  : 
 T A=4 !. DataSet  ?  *
 5 $ 1 *,   *2 4 8 % 
:.  !   * 7 C   *
  DataView
9  
 ? (4  
9 [   /0. DataView . + . O ddNe
A
.9 0. !  @ P - !
    w
 ?  $ 9 [   /0. DataView. Delete
*       # 2 % $  @ *+   /0. 0G `Find
.  /0.  I0 9,
 T>  8
      # 2 % $  @ 0G FindR
ows
DataRow .  /0.  !

:8
Dim strSQL As String = "SELECT * FROM Products"
Dim sda As New SqlDataAdapter(strSQL, connStr)
Dim ds As New DataSet()

sda.Fill(ds, "ProductInfo")

Dim dv As New DataView(ds.Tables(“ProductInfo”))

dv.Sort = “Prod_Name ASC”

dv.RowFilter = “In_Stock > 100”

‘ Bind the DataGrid to this DataView.


Me.dgdDemo.DataSource = dv

449 ADO.NET @ E&


:DataReader @ A
 7+ ! + , T W  ! 5  (4 *,    2 DataSet  T2 
 &  5  (4 *,      (4   P$ ! 3, ! > 5&$
.5  1 
$ (4
: $ *,$ 1
2  DataReader  ?  

Universal Knowledge Solutions s.a.l 187


%$ *$   @ $ 2 7+2 2 *
 $ •
MDELETEUPDATE INSERT SQL 5  0 # •
DataSet  T2   1 2  +2 5   % +  +     + 8 •
 
 +$ 8  •

:DataReader  ?   2 8 3.


OLE-DB  . OleDbDataReader  ? •
SQLServer    
 5  5  I0 SqlDataReader  ? •
 8
 $&  5 W
4  2 SQL  , 0 # DataReader  ? 
5@ 30 ! 5   1 *& (,8 X$  04      *
 5  9#
5   ! 5   1  5 =J, C = DataReader  ?  •
9# 8
 ;&  5 W
- 2 SQL
5  K $  5 W
4 2 SQL 5 , 0 #  +4 DataReader  ?  •
5  (4 * T *  ? 0.  & •
 %A ,  *. DataReader  ?  4 = ! 9# 8
 (4 *
$ /


ADO.NET @ E&

:DataReader @ A 449 : 


2 SQL 5  0 # C 7 Command  T A=[  DataReader  T &
.DataReader  T %84  5 W
4
 VW ;& DataReader  ?  %8> 9# /0. 8   . +

Universal Knowledge Solutions s.a.l 188


.5  

:  !. < DataReader  ?   7+2


$  
 K $ !  (4 =J  > (4 % 9 =J 1  Read
.C  *, @ 2    %8>  @ (4 *
5   ! R    # !$ 9   @   GetVal
ue
+   7+2 + 2 *+=  ,8 0 # . *   $ 30
. *+= 30 % =   
Value=DataReader(“col-Name”)
30 !,>    !$ 9   @ 8
 2  @ %8  GetVal
ues
.# 
$ $ 5     !$    @ %8[  Getxxx
xxx
.xxxxxx  
GetBoolean,GetInt16,GetChars. *7
8 B > 9# 8
 (4 9 =J *   /0.  NextRe
sult
.9# 8
  7+2 %8[   W
- 2 SQL  , 
 > MoveNext  ,  = 5    /0. 2 (4 % =- 

.B 2 (4 9# 8
  * 9# 8
 #  *&
(4 = I0 =J $DataReader  ? ;T[  Close
.9# 8


ADO.NET @ E&

:DataSet @ E " 4 ) 0  DataReader @ E " 4 ) 0 


9 +   I0 * U +# 2  ,8
5   (4 *,   A A 8
.5  *  

Universal Knowledge Solutions s.a.l 189


C.4 + &   *$  DataSet  T2 2 < / +0  '  '2 C2  &
 (,8  +    & <04 .% +0 3;  A> K $  DataReader  ? 1  
8 A?&   + & ! 5&$  3. 2 &4 .DataSet 8 <8 DataReader  ?
:!. DataSet
2 (4 5  /0.  5   1 * T *+= 5   (4 
$ 8 •
. $        B 2

 (DataTable  T  7+2) *
 7+2 (4 * *   (4 
$ 8 •
*
 /0.  5@;
 DataSet  ?     5  %8@ ! 5  K $ (4 
$ 8 •
 5 W
-  2 SQL UPDATE 5   8 <8 DataAdapter
 % W  ! *2 *+= 1 % - 
$ 8 •
,  W; 9# 8
 XML W7    %#&   8 •
2 5@ # ! 8  7+2 1   5&$ *7 +$ 8 1   5&$  ! •
DataView  ? $ /0. !  04 DataGrid +$ 8 ! 5$# (4 5;
  
DataSet  T ! *
 G=
2 d + $ /
 !  $ (,8 *$  2 5  9#     2 *$ ! •
DataReader  ?  + & < 2 . .9,

:8

SqlConnection conn = new SqlConnection(connectionString);


SqlCommand comm = new SqlCommand("select * from mytable", conn);
comm.Connection.Open();
SqlDataReader r =
comm.ExecuteReader(CommandBehavior.CloseConnection);
while(r.Read())

Universal Knowledge Solutions s.a.l 190


Console.WriteLine(r.GetString(0));
}
r.Close();
conn.Close()

.NET 52 C.# 


 *

8 .NET *8 4  . 5   *; 5  5 .NET  <  2 +
:  5 8

$ * 4
OLE-DB * SQLServer SQLOLEDB
OLE-DB * ORACLE MSDAORA
OLE-DB* Access  Microsoft.Jet.OLEDB.4.0
  ! 5 Jet

5   5


    *& '  /   I0 ODBC  < 2 .NET 
OdbcConnection ;
< 7    B > 5 1  3,  =  T2  .
.f4...OdbcDataAdapter OdbcDataReader OdbcCommand

8&

OleDbConnection @ A " 4 8

<%@ Import Namespace="System.Data.OleDb" %>


<script runat="server">
sub Page_Load
dim dbconn
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("northwind.mdb"))
dbconn.Open()
end sub
</script>

Command @ A " 4 8

<%@ Import Namespace="System.Data.OleDb" %>


<script runat="server">
sub Page_Load
dim dbconn,sql,dbcomm

Universal Knowledge Solutions s.a.l 191


dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("northwind.mdb"))
dbconn.Open()
sql="SELECT * FROM customers"
dbcomm=New OleDbCommand(sql,dbconn)
end sub
</script>
DataReader @ A " 4 8

<%@ Import Namespace="System.Data.OleDb" %>


<script runat="server">
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("northwind.mdb"))
dbconn.Open()
sql="SELECT * FROM customers"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
end sub
</script>

DataView  DataAdapter  DataSet @ E " 4 8

<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>


<%@Import Namespace="System.Data.OleDb" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>The .NET DataSet and OleDbDataAdapter Objects</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">The .NET DataSet and OleDbDataAdapter
Objects</span><hr />
<!-----------------------------------------------------------------
---------->

<div>Connection string: <b><span id="outConnect"


runat="server"></span></b></div>
<div>SELECT command: <b><span id="outSelect"
runat="server"></span></b></div>
<div id="outError" runat="server">&nbsp;</div>

<asp:datagrid id="dgrResult" runat="server" />

<script language="vb" runat="server">


Universal Knowledge Solutions s.a.l 192
Sub Page_Load()

'get connection string from web.config file


Dim strConnect As String
strConnect = ConfigurationSettings.AppSettings("DsnWroxBooksJet") _
& Request.PhysicalApplicationPath _
& "databases\WroxBooks.mdb"
outConnect.innerText = strConnect 'and display it

'specify the SELECT statement to extract the data


Dim strSelect As String
strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '07645437%'"
outSelect.innerText = strSelect 'and display it

'declare a variable to hold a DataSet object


'note that we have to create it outside the Try..Catch block
'as this is a separate block and so is a different scope
Dim objDataSet As New DataSet()

Try

'create a new Connection object using the connection string


Dim objConnect As New OleDbConnection(strConnect)

'create a new DataAdapter using the connection object and select


statement
Dim objDataAdapter As New OleDbDataAdapter(strSelect, objConnect)

'fill the dataset with data from the DataAdapter object


objDataAdapter.Fill(objDataSet, "Books")

Catch objError As Exception

'display error details


outError.innerHTML = "<b>* Error while accessing data</b>.<br />" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution

End Try

'create a DataView object for the Books table in the DataSet


Dim objDataView As New DataView(objDataSet.Tables("Books"))

'assign the DataView object to the DataGrid control


dgrResult.DataSource = objDataView
dgrResult.DataBind() 'and bind (display) the data

End Sub
</script>

Universal Knowledge Solutions s.a.l 193


<!-----------------------------------------------------------------
---------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>

:DataRow  DataColumn  DataTable  DataSet " 4 8

Dim ds As New DataSet()

Dim strSQL As String = "SELECT Cust_ID, Order_Id, “ & _


“Order_Date FROM Orders WHERE Year(Order_Date) > 1997"
Dim oda As New OleDbDataAdapter(strSQL, connStr)
oda.Fill(ds, "OrderInfo")

strSQL = "SELECT CustomerID FROM Customers “ & _


“ORDER BY CustomerID"
Dim sda As New SqlDataAdapter(strSQL, connStr)
sda.Fill(ds, "CustomerInfo")

Dim dc1 As DataColumn = _


ds.Tables("CustomerInfo").Columns("CustomerId")
Dim dc2 As DataColumn = _
ds.Tables("OrderInfo").Columns("Cust_Id")

Dim dr As New DataRelation("CustomersToOrders", dc1, dc2)


ds.Relations.Add(dr)

Dim drCustomer As DataRow


Dim drOrder As DataRow

For Each drCustomer In ds.Tables("CustomerInfo").Rows


lstDemo.Items.Add("Customer: " & _
drCustomer("CustomerId").ToString())
' Iterate through related rows.
For Each drOrder In drCustomer.GetChildRows(dr)
lstDemo.Items.Add( _
String.Format(" Order {0} placed on {1:d}", _
drOrder("Order_ID"), drOrder("Order_Date")))
Next drOrder
Next drCustomer

.NET 52 XML  

@  W; 5  (4 *,  .NET * 4 ! % 
   8 < ,+
.ADO 1  5+ !   , 5  1    
Universal Knowledge Solutions s.a.l 194
0 .5     *@  .8   (,8  > ?, 8  XML ? 5$2
XML ? .NET   8 !   (,8 A
 0. ! + 

:.NET 52 449 XML @ E&


  5   
! 5
   5$ !   8
 W3C X 5@
*;   /0. 8 .NET 5 @ .(DOM) 6  /0. ( .XML W7 (4 *,
.XmlDataDocument  XmlDocument  T>

. 7 
  (DOM) XML  ;
< + <8  T> /0. 

.NET 52 XML 0;  

5#, XML *+ . XML W7 1 *, 5    8 XML J*  8 .NET 5
:XML W7 1 *,   !  T> '  !,   . >

Universal Knowledge Solutions s.a.l 195


:58
 K;7 !  > XML  T2 U
 XmlTextReader  T2 8
 /0.  XML 5#, * $ + %A  (> •
9, A=[  XslTransform  T (4 4 XmlNodeReader  XmlTextWriter
. ,> XML  7 8 9,  
XmlDocument *7  T>  !.   * XML W7    7 •
.XPathDocument XmlDataDocument
.XPathNavigator  ?    XML ;  !  77 2 •
 ?   A @ A72 XML  7 ; .9WX /0.  * X$; 1
+ + .XML 5 *+ . $ A=- B 2  T2 3. XmlValidatingReader
.9,   (4  , $ (4 -  7 (,8 ; 0 # XslTransform  ?  < 2

Document @ E&

:Document  ?    5 H K;7  

Universal Knowledge Solutions s.a.l 196


W  .Dom  .Net    H 8 % 8 . :XmlDocument  ? •
*
 5-  1 XML W7 1 *, W3C *@    3,  ? 0.  
.* 2  > 5 ,

#  XmlDocument  ?,  8 % 8 . :XmlDataDocument  ? •


. W; 5  8@ W  XML  * 
+ * +   W 8


  <   . XML W7     H *7 XPathDocument  ? •


 $; 2  XPath 5; * XPathNavigator  ?  C 4 *
.“Pull”    ] , 8  7

:Document @ E9 449 : 

 C+ CreateNavigator   T %W 50 8   XPathDocument  ? 3, &
8
 Document  ?  ] 8  $ ! .XPathNavigator  ? 1  * 
0.  +0  4 .W3C DOM  ! %$ 3, !. W    ,+
!. XML W7 1 *, + *+=  ! W    % # 8
 8
.%
 8 (4 *     U2 A=-   

9  
*7    (,8 <8 XML  7 ! %8 A=[  Createxxxxx
x
CreateComment CreateElement
f4...CreateTextNode
%8   *7 XML %8 8 , 7  A=[  CloneNode
Element
.*+ ID #  @  % $ %8 %8[  GetElementB
yId
*+ % =G   % $ %8 %8[  GetElements
ByTagname

.XML  7  T (4  XML X#$ * $    8


 < 2 3.
Universal Knowledge Solutions s.a.l 197
2 Stream  T (4 2   (,8 9, (4 ,+ XML  7 X#$  Save
.XmlTextWriter  ?u4
 ?  4 =G I
XML  7  %8 * $  Read
Node
.XmlNodeReader  T 2 XmlTextReader
 ?  4 =G I
XML  7 (4 %8 +  Write
To
XmlTextWriter
=G I
B 2 XML  7 (4  $ P   *+ %8 +  i rite
W
.XmlTextWrite  ?  4 Cont
entT
o

( #
 ) Document @ E9 449 : 

   /A=[  [  7 ! XPathNavigator  ? *  2 04 2
:CreateNavigator
$  
 7 (,8 ! XPathNavigator  T %84 A=[  CreateNavigator
. $XML
1 . Document  T2 U2 1 
(,8 C  +
  /0. *XmlDataDocument  XmlDocument
+ !  7 ! %8 (4 =J *+= !4 *
XPathNavigator  ?   1@

: XmlDocument  ?   W 8  4  XmlDataDocument  T 8


$ "
.DataSet  ?+ XML  7 B$ %8[  DataSe
t

Universal Knowledge Solutions s.a.l 198


 7 B$ (4 B@2 *    4   XmlDataDocument  ? 8 30+
.5  *
2 9# 8
+   * 30
$  
 T   DataRow  *7 GetRowFromElement
. 7 !
 T   XmlElement *7 GetElementFromRow
DataRow  *
! DataSet

XPathNavigator @ A

A> A ! XPathNavigator  ? 9   * 2 XML W7 1 * *



 7  + 8 ;; 2 XML  7  *
, C + I0 System.Xml
. XPath  

1    XML  7  T I2 1 XPathNavigator  ? C + C2 (4 =


XMLDocument  T (,8 ! XPathNavigator  T A=4 + I2 .XPathDocument
.XmlDataDocument  T (,8 2

XML  7  *
 ' ! W    8
 XPathNavigator  ? 
.    %8 (4 * ($  
 2     *&+

2 % 2 XPath 5  * !    8


 XPathNavigator  ? 
. /0. 8 *
 1  .8 .  8
 2 %   %

:!, + 30 


  7  T   XPathNavigator  ? A=4 +

Dim objNav1 As XPathNavigator = objXMLDoc.CreateNavigator()


Dim objNav2 As XPathNavigator = objXMLDataDoc.CreateNavigator()
Dim objNav3 As XPathNavigator = objXPathDoc.CreateNavigator()

Universal Knowledge Solutions s.a.l 199


XPathNavigator @ A 449 : 

7+2 A=4 + . 4 * XML  7  %8    7 8 *


  ? 0. '
. @    7 # (,8 U 0.   T 
I0 XPathNodeIterator  T 2  ? 0   $ % (4 =J  XML  7 $
.8
   %    A8    8
  7+2 I$
    + 0   $ % *$ * # XPathNavigator  ?  5@ # !
. 7   %8 5, (4 *,
 7  + $,   3. .< XPathNavigator  ?   7+2 ' *
!,  
XPathNavigator  T A=-2 XPathNavigator  ?   $ % !.  %8 *

: 

9  
  . $ XML  7   ? 1@ 3 $  MoveToxxxxxx
MoveToFirst ,MoveToRoot ,MoveToAttribute, :; < 7
moveToParent,MoveToFirstChild..
+ # ! 1  
XPathNavigator  T A=4 Clone
. 7  XPathNavigator !$  T C  1 I0

: 7 B$  A


2   *,    < 2 3.
9  
. ?,  $ %  $ * %$   %8[  GetAttribute
  8
 I$ I0 XPathNodeIterator  T   Select
.XPath   !
(,8 I$ XPathNodeIterator  T   /0.   SelectAncest
ors
     !  7 ! 9, 8 1 
 8

. 
  8
 I$ XPathNodeIterator  T   SelectDescen
dants
.  2     !  7  % $
  8
 I$ XPathNodeItarator  T   SelectChildre

Universal Knowledge Solutions s.a.l 200


 2    A> n

XmlTextWriter @ A

 
 4 A
2 A=4  ,8
% 
XML  7 A=- XmlDocument  ?  8
.G,  % + @   !.      7
+  ,,   B > , %8 XML  7 A=-  R 2 XmlWriter  ?, +
. ? 0.   !   8
  P  (4 B$ 5 =G
   (,8 9, (4 = I0 TextWriter  T 4  + XmlTextWriter  ? 0G
. % 
XML  7 I$ I0 Stream  T 2 9, 0.   
5 $ XML 8 A=-   + !   W  8
  ? 0.  •
.% = %  Stream  T 2   (,8 9, (4 P  C
  7 B 2
 T  K $ %  T2 !   P  %G+ XmlTextWriter  ?   2 + •
Stream  T 2 TextWriter  T 2   (,8 9, (4 B$ C
 XmlTextWriter

:  !.  ? 0  <   7+ :XmlTextWriter @ A 449 : 


9  
.P  (4 XML '  + % 
 7 2  WriteStartDocument
* 4 7 ,? T  1 
;T[  7 A [  WriteEndDocument
.P  (4 B$
A=[ A + .8 .$  % =G '#  WriteStartElement
WriteStartAttribute    5#
,   .!$ , ;T4 % =G +  iWriteEndElement
.WriteEndAttribute !. # ;T-
(;T- '# 5 =G  ) *+ 8 +  iWriteElementString
, # A> ,   . + 9 $ , 
.WriteAttributeString !. 5# 1
$Stream  T 2   (,8 9, ;T[  Close
.  5 =J 1 

Universal Knowledge Solutions s.a.l 201


XmlReader @ A

. + 8 <8 H   XML W7 %A @ (4  $>  ! P$

 XmlTextReader . 8 # C K I8@ 9 XmlReader  ? 


.XmlNodeReader
(,8 XML 9, (4 =J I0 TextReader  ? (,8 XmlTextReader  ?  •
%8  7 B$ %A @ + .XML  7 I$ Stream  T (42 C /  (4  
. A @ A72  $ !   *$ %8 *+ *$ 5,  ?   B > ,
 7  A
%A  '  C + XmlNode  T XmlNodeReader  ? 0G •
/0  A>  (4   %8 (4 * . + *$ !  7 *+ %A @ 8 <8 XML
.%
 ,# %  XmlNodeReader  XmlTextReader  ?  R 2 + •
   7 %A  < W,  K $ B 2  T> + 2 XML W7 * 1  *
. >  ? (4 %A  V

%8 5  (4 *, “pull” 


0 XmlTextReader  XPathNavigator  T> 
% + 5#, (4 * 30 ' .% +0  %
=+  7 *+ c # 8 <8 B > ,
.5&$ ,T2 I- * 2 !
   +  ,8 *
    7+ 3;   
$

*+ %A @ (4   .8    @ 8   K$ ! 5&$ !  T> /0.  .2   +
. 7  A
%A @  %$ %8 (4 * + *  7

XmlReader @ A 449 : 

Universal Knowledge Solutions s.a.l 202


  .2 <     W XmlNodeReader  XmlTextReader  ? 3,
:!. 
$  
  . 4 * + K $  ? (4   % %A   Read
. A  8 I2 ( & 8 False  
1 
   9 $ ,, *+= % B$ %84 %A   ReadInnerX
ml
.A> ,  5 =G
9 $ ,,+  $ %  7D  B$ %84 %A   ReadOuterX
ml
. A> ,  5 =G 1 
  
. $ %  @ I$ 9 $ ,, %8[  ReadString
XmlReader  ?  $ %, %$ #  @ %8[  GetAttribute
,,+   XML  7  !@ A
 %84 %A   GetRemaind
er
 7  XML * T  8 % #   /0.  9 $
.B 2 (4
 MoveToAttribute :*7 .v  =J 1@ *  MoveToxxx
xxx
MoveToElement  MoveToContent
.  % (4 3 $  $ % 
  Skip
 I0 Stream  ? ;T4 2   (,8 9, ;T[  Close
.C *

XMLValidatingReader @ A
. XmlValidatingReader  ? . XmlReader 9 (,8 ! H  T 3.
 2 *+  <    7     + XmlTextReader  ?+  ? 0. (4 X +
.
Stream  T  2 
 XmlReadr  T  XmlValidatingReader  T A=4 +
.  $      XML I$ 9 $ ,,  2

:XslTransform @ A
.XML W7 1 * 5, .2  XSTL 2 XSL   7 * $ (4 
$ 

Universal Knowledge Solutions s.a.l 203


2 XSL  * $ 5 ,8 A
- <   XslTransform  ? .NET 
.XSTL

:XslTransform @ A 449 : 
:.  2   XslTrasform 
9  
 XSL 2  7 * $  Load
 2  7 I2 (4 =G
xsl:include
Xml  7 5  * $  Transform
XSLT 2 XSL %$
.V P [

8

Load   C 4 9, * $ @ 7 XmlDocument  ?  2 *7 0. ! X$;
  % =G + !  1 

- GetElementByTagname    @ .
..  X4 VW    @ 7 “AutherName” .
<%@Page Language="VB" %>
<%@Import Namespace="System.XML" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Searching an XML document using the DOM</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Searching an XML document using the
DOM</span><hr />
<!-----------------------------------------------------------------
---------->

<div id="outDocURL" runat="server"></div>


<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="vb" runat="server">

Sub Page_Load()

Universal Knowledge Solutions s.a.l 204


'create physical path to booklist.xml sample file (in same folder
as ASPX page)
Dim strCurrentPath As String = Request.PhysicalPath
Dim strXMLPath As String = Left(strCurrentPath,
InStrRev(strCurrentPath, "\")) & "booklist.xml"

'create a new XMLDocument object


Dim objXMLDoc As New XmlDocument()

Try

'load the XML file into the XMLDocument object


objXMLDoc.Load(strXMLPath)
outDocURL.innerHTML = "Loaded file: <b>" & strXMLPath & "</b>"

Catch objError As Exception

'display error details


outError.innerHTML = "<b>* Error while accessing document</b>.<br
/>" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution

End Try

'now ready to parse the XML document


'it must be well-formed to have loaded without error

'create a string to hold the matching values found


Dim strResults As String = "<b>List of authors</b>:<br />"

'create a NodeList collection of all matching child nodes


Dim colElements As XmlNodeList
colElements = objXMLDoc.GetElementsByTagname("AuthorName")

'iterate through the collection getting the values of the


'child #text nodes for each one
Dim objNode As XmlNode
For Each objNode In colElements
strResults += objNode.FirstChild().Value & "<br />"
Next

'then display the result


outResults.innerHTML = strResults 'display the result

End Sub

</script>

</body>

Universal Knowledge Solutions s.a.l 205


</html>

:8
   C 4 XML  7 * $ 7 XmlDocument  T   ! *7 !
. Load
. NodeType   /  I0 @  (,8 <A  7  % U %8[   1 9  @
.%8 *+ A>  $     H 1 9  @ 7
<%@Page Language="VB" %>
<%@Import Namespace="System.XML" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Accessing XML documents using the DOM</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Accessing XML documents using the
DOM</span><hr />
<!-----------------------------------------------------------------
---------->

<div id="outDocURL" runat="server"></div>


<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="vb" runat="server">

Sub Page_Load()

'create physical path to booklist.xml sample file (in same folder


as ASPX page)
Dim strCurrentPath As String = Request.PhysicalPath
Dim strXMLPath As String = Left(strCurrentPath,
InStrRev(strCurrentPath, "\")) & "booklist.xml"

'create a new XMLDocument object


Dim objXMLDoc As New XMLDocument()

Try

'load the XML file into the XMLDocument object


objXMLDoc.Load(strXMLPath)
outDocURL.innerHTML = "Loaded file: <b>" & strXMLPath & "</b>"

Catch objError As Exception

Universal Knowledge Solutions s.a.l 206


'display error details
outError.innerHTML = "<b>* Error while accessing document</b>.<br
/>" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution

End Try

'now ready to parse the XML document


'it must be well-formed to have loaded without error
'call a recursive function to iterate through all the nodes
'in the document creating a string that is placed in the <div>
above
Dim strNodes As String
outResults.innerHTML = strNodes &
GetChildNodes(objXMLDoc.ChildNodes, 0)

End Sub

Function GetChildNodes(objNodeList As XMLNodeList, intLevel As


Integer) As String

Dim strNodes As String = ""


Dim objNode As XMLNode
Dim objAttr As XMLAttribute

'iterate through all the child nodes for the current node
For Each objNode In objNodeList

'display information about this node


strNodes = strNodes & GetIndent(intLevel) _
& GetNodeType(objNode.NodeType) & ": <b>" & objNode.Name

'if it is an XML Declaration node, display the 'special' properties


If objNode.NodeType = XMLNodeType.XmlDeclaration Then
'cast the XMLNode object to an XmlDeclaration object
Dim objXMLDec =CType(objNode, XmlDeclaration)
strNodes = strNodes & "</b>&nbsp; version=<b>" & objXMLDec.Version
_
& "</b>&nbsp; standalone=<b>" & objXMLDec.Standalone & "</b><br />"
Else
'just display the generic 'value' property
strNodes = strNodes & "</b>&nbsp; value=<b>" & objNode.Value &
"</b><br />"
End If

'if it is an Element node, iterate through the Attributes


'collection displaying information about each attribute
If objNode.NodeType = XMLNodeType.Element Then

Universal Knowledge Solutions s.a.l 207


'display the attribute information for each attribute
For Each objAttr In objNode.Attributes
strNodes = strNodes & GetIndent(intLevel + 1) _
& GetNodeType(objAttr.NodeType) & ": <b>" & objAttr.Name _
& "</b>&nbsp; value=<b>" & objAttr.Value & "</b><br />"
Next
End If

'if this node has child nodes, call the same function recursively
'to display the information for it and each of its child node
If objNode.HasChildNodes Then
strNodes = strNodes & GetChildNodes(objNode.childNodes, intLevel +
1)
End If

Next 'go to next node

Return strNodes 'pass the result back to the caller

End Function

Function GetIndent(intLevel As Integer)


'returns a string of non-breaking spaces used to indent each line
Dim strIndent As String = ""
Dim intIndent As Integer
For intIndent = 0 To intLevel
strIndent = strIndent & "&nbsp; &nbsp; &nbsp; "
Next
Return strIndent
End Function

Function GetNodeType(intType As Integer) As String


'returns the node type as a string
Select Case (intType)
Case 0: Return "NONE"
Case 1: Return "ELEMENT"
Case 2: Return "ATTRIBUTE"
Case 3: Return "TEXT"
Case 4: Return "CDATA SECTION"
Case 5: Return "ENTITY REFERENCE"
Case 6: Return "ENTITY"
Case 7: Return "PROCESSING INSTRUCTION"
Case 8: Return "COMMENT"
Case 9: Return "DOCUMENT"
Case 10: Return "DOCUMENT TYPE"
Case 11: Return "DOCUMENT FRAGMENT"
Case 12: Return "NOTATION"
Case 13: Return "WHITESPACE"
Case 14: Return "SIGNIFICANT WHITESPACE"
Case 15: Return "END ELEMENT"

Universal Knowledge Solutions s.a.l 208


Case 16: Return "END ENTITY"
Case 17: Return "XML DECLARATION"
Case 18: Return "NODE (ALL)"
Case Else: Return "UNKNOWN"
End Select
End Function

</script>

</body>
</html>

:*7
.   XPathNavigator  ? 1 XmlDocument  ? ! *7 ! 
 *7 #   XMLNode  ?
<%@Page Language="VB" %>
<%@Import Namespace="System.Xml" %>
<%@Import Namespace="System.Xml.Xpath" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Accessing XML documents using an XPathNavigator</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Accessing XML documents using an
XPathNavigator</span><hr />
<!-----------------------------------------------------------------
---------->

<div id="outDocURL" runat="server"></div>


<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="vb" runat="server">

Sub Page_Load()

'create physical path to booklist.xml sample file (in same folder


as ASPX page)
Dim strCurrentPath As String = Request.PhysicalPath
Dim strXMLPath As String = Left(strCurrentPath,
InStrRev(strCurrentPath, "\")) & "booklist.xml"

'create a new XmlDocument object


Dim objXMLDoc As New XmlDocument

Try

Universal Knowledge Solutions s.a.l 209


'load the XML file
objXMLDoc.Load(strXMLPath)
outDocURL.innerHTML = "Loaded file: <b>" & strXMLPath & "</b>"

Catch objError As Exception

'display error details


outError.innerHTML = "<b>* Error while accessing document</b>.<br
/>" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution

End Try

'now ready to parse the XML document


'it must be well-formed to have loaded without error
'create a new XPathNavigator object using the XMLDocument object
Dim objXPNav As XPathNavigator = objXMLDoc.CreateNavigator()

'move the current position to the root #document node


objXPNav.MoveToRoot()

'call a recursive function to iterate through all the nodes in the


'XPathNavigator, creating a string that is placed in the <div>
above
outResults.innerHTML = GetXMLDocFragment(objXPNav, 0)

End Sub

Function GetXMLDocFragment(objXPNav As XPathNavigator, intLevel As


Integer) As String

Dim strNodes As String = ""


Dim intLoop As Integer

'display information about this node


strNodes = strNodes & GetIndent(intLevel) _
& GetNodeType(objXPNav.NodeType) & ": <b>" & objXPNav.Name _
& "</b>&nbsp; value=<b>" & objXPNav.Value & "</b><br />"

'see if this node has any Attributes


If objXPNav.HasAttributes Then

'move to the first attribute


objXPNav.MoveToFirstAttribute()

Do

'display the information about it

Universal Knowledge Solutions s.a.l 210


strNodes = strNodes & GetIndent(intLevel + 1) _
& GetNodeType(objXPNav.NodeType) & ": <b>" & objXPNav.Name _
& "</b>&nbsp; value=<b>" & objXPNav.Value & "</b><br />"

Loop While objXPNav.MoveToNextAttribute()

'then move back to the parent node (i.e. the element itself)
objXPNav.MoveToParent()

End If

'see if this node has any child nodes


If objXPNav.HasChildren Then

'move to the first child node of the current node


objXPNav.MoveToFirstChild()

Do
'recursively call this function to display the child node fragment
strNodes = strNodes & GetXMLDocFragment(objXPNav, intLevel + 1)
Loop While objXPNav.MoveToNext()

'move back to the parent node - the node we started from when we
'moved to the first child node - could have used Push and Pop
instead
objXPNav.MoveToParent()

End If

'must repeat the process for the remaining sibling nodes (i.e.nodes
'at the same 'level' as the current node within the XML document
'so repeat while we can move to the next sibling node
Do While objXPNav.MoveToNext()

'recursively call this function to display this sibling node


'and its atributes and child nodes
strNodes = strNodes & GetXMLDocFragment(objXPNav, intLevel)

Loop

Return strNodes 'pass the result back to the caller

End Function

Function GetIndent(intLevel As Integer)


'returns a string of non-breaking spaces used to indent each line
Dim strIndent As String = ""
Dim intIndent As Integer
For intIndent = 0 To intLevel
strIndent = strIndent & "&nbsp; &nbsp; &nbsp; "

Universal Knowledge Solutions s.a.l 211


Next
Return strIndent
End Function

Function GetNodeType(intType As Integer) As String


'returns the node type as a string
Select Case (intType)
Case 0: Return "NONE"
Case 1: Return "ELEMENT"
Case 2: Return "ATTRIBUTE"
Case 3: Return "TEXT"
Case 4: Return "CDATA SECTION"
Case 5: Return "ENTITY REFERENCE"
Case 6: Return "ENTITY"
Case 7: Return "PROCESSING INSTRUCTION"
Case 8: Return "COMMENT"
Case 9: Return "DOCUMENT"
Case 10: Return "DOCUMENT TYPE"
Case 11: Return "DOCUMENT FRAGMENT"
Case 12: Return "NOTATION"
Case 13: Return "WHITESPACE"
Case 14: Return "SIGNIFICANT WHITESPACE"
Case 15: Return "END ELEMENT"
Case 16: Return "END ENTITY"
Case 17: Return "XML DECLARATION"
Case 18: Return "NODE (ALL)"
Case Else: Return "UNKNOWN"
End Select
End Function

</script>

<!-----------------------------------------------------------------
---------->
</body>
</html>

XmlTextReader  ?  %  /0.  ,7d C= * 
<%@Page Language="VB" %>
<%@Import Namespace="System.XML" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Accessing an XML document with an XMLTextReader
object</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
Universal Knowledge Solutions s.a.l 212
<span class="heading">Accessing an XML document with an
XMLTextReader object</span><hr />
<!-----------------------------------------------------------------
---------->

<div id="outDocURL" runat="server"></div>


<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="vb" runat="server">

Sub Page_Load()

'create physical path to booklist.xml sample file (in same folder


as ASPX page)
Dim strCurrentPath As String = Request.PhysicalPath
Dim strXMLPath As String = Left(strCurrentPath,
InStrRev(strCurrentPath, "\")) & "booklist.xml"

'declare a variable to hold an XmlTextReader object


Dim objXMLReader As XmlTextReader

Try

'create a new XmlTextReader object for the XML file


objXMLReader = New XmlTextReader(strXMLPath)
outDocURL.innerHTML = "Opened file: <b>" & strXMLPath & "</b>"

Catch objError As Exception

'display error details


outError.innerHTML = "<b>* Error while accessing document</b>.<br
/>" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution

End Try

'now ready to read (or "pull") the nodes of the XML document
Dim strNodeResult As String = ""
Dim objNodeType As XmlNodeType

'read each node in turn - returns False if no more nodes to read


Do While objXMLReader.Read()

'select on the type of the node (these are only some of the types)
objNodeType = objXMLReader.NodeType

Select Case objNodeType

Case XmlNodeType.XmlDeclaration:

Universal Knowledge Solutions s.a.l 213


'get the name and value
strNodeResult += "XML Declaration: <b>" & objXMLReader.Name _
& " " & objXMLReader.Value & "</b><br />"

Case XmlNodeType.Element:
'just get the name, any value will be in next (#text) node
strNodeResult += "Element: <b>" & objXMLReader.Name & "</b><br />"

Case XmlNodeType.Text:
'just display the value, node name is "#text" in this case
strNodeResult += "&nbsp; - Value: <b>" & objXMLReader.Value _
& "</b><br />"

End Select

'see if this node has any attributes


If objXMLReader.AttributeCount > 0 Then

'iterate through the attributes by moving to the next one


'could use MoveToFirstAttribute but MoveToNextAttribute does
'the same when the current node is an element-type node
Do While objXMLReader.MoveToNextAttribute()

'get the attribute name and value


strNodeResult += "&nbsp; - Attribute: <b>" & objXMLReader.Name _
& "</b> &nbsp; Value: <b>" & objXMLReader.Value _
& "</b><br />"
Loop

End If

Loop 'and read the next node

'finished with the reader so close it


objXMLReader.Close()

'and display the results in the page


outResults.innerHTML = strNodeResult

End Sub

</script>
<!-----------------------------------------------------------------
---------->
</body>
</html>

:*7
X$; .C XMl  7 +  XMLTextWriter  ?   ! *7 !

Universal Knowledge Solutions s.a.l 214


2 7  (   $- )    $ @ 7 XmlTextWriter  ? A=[ 2 2
 WriteComment  WriteStartDocument *7  ?     7 +
....WriteStartElement
.Close  flush    9, ,T4 9, (4  ? B$ c # @ 7

 +$ 8 (4 B$ + @ 7 9 $ , (4 /$ * $ 9, '# @ .
OurResult

<%@Page Language="VB" %>


<%@Import Namespace="System.XML" %>
<%@ Import Namespace="System.IO" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<html><head>
<title>Creating an XML document with an XMLTextWriter
object</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Creating an XML document with an
XMLTextWriter object</span><hr />
<!-----------------------------------------------------------------
---------->

<div id="outDocURL" runat="server"></div>


<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="vb" runat="server">

Sub Page_Load()

'create physical path for the new file (in same folder as ASPX
page)
Dim strCurrentPath As String = Request.PhysicalPath
Dim strXMLPath As String = Left(strCurrentPath,
InStrRev(strCurrentPath, "\")) & "newbooklist.xml"

'declare a variable to hold an XmlTextWriter object


Dim objXMLWriter As XmlTextWriter

Try

'create a new objXMLWriter object for the XML file


objXMLWriter = New XmlTextWriter(strXMLPath, Nothing)
outDocURL.innerHTML = "Writing to file: <b>" & strXMLPath & "</b>"

Universal Knowledge Solutions s.a.l 215


Catch objError As Exception

'display error details


outError.innerHTML = "<b>* Error while accessing document</b>.<br
/>" _
& objError.Message & "<br />" & objError.Source
Exit Sub ' and stop execution

End Try

'now ready to write (or "push") the nodes for the new XML document

'turn on indented formatting and set indent to 3 chararcters


objXMLWriter.Formatting = Formatting.Indented
objXMLWriter.Indentation = 3

'start the document with the XML declaration tag


objXMLWriter.WriteStartDocument()

'write a comment element including the current date/time


objXMLWriter.WriteComment("Created using an XMLTextWriter - " &
Now())

'write the opening tag for the <BookList> root element


objXMLWriter.WriteStartElement("BookList")

'write the opening tag for a <Book> element


objXMLWriter.WriteStartElement("Book")

'add two attributes to this element's opening tag


objXMLWriter.WriteAttributeString("Category", "Technology")
Dim intPageCount As Integer = 1248 'numeric value to convert
objXMLWriter.WriteAttributeString("Pagecount",
intPageCount.ToString("G"))

'write four elements, using different source data types


objXMLWriter.WriteElementString("Title", "Professional Video
Recorder Programming")
Dim datReleaseDate As DateTime = #03/03/2000#
objXMLWriter.WriteElementString("ReleaseDate",
datReleaseDate.ToString("yyyy-MM-dd"))
Dim intSales As Integer = 17492
objXMLWriter.WriteElementString("Sales", intSales.ToString("G"))
Dim blnHardback As Boolean = True
objXMLWriter.WriteElementString("Hardback", blnHardback.ToString())

'write the opening tag for the <AuthorList> child element


objXMLWriter.WriteStartElement("AuthorList")

'add two <Author> elements


objXMLWriter.WriteElementString("Author", "Francesca Unix")

Universal Knowledge Solutions s.a.l 216


objXMLWriter.WriteElementString("Author", "William Soft")

'close the <AuthorList> element


objXMLWriter.WriteEndElement()

'close the <Book> element


objXMLWriter.WriteEndElement()

'close the root <BookList> element


objXMLWriter.WriteEndElement()

'flush the current content to the file and close it


objXMLWriter.Flush()
objXMLWriter.Close()

'now open the new XML file and read it into a string
Dim strXMLResult As String
Dim objSR As StreamReader = File.OpenText(strXMLPath)
strXMLResult = objSR.ReadToEnd()
objSR.Close
objSR = Nothing

'and display the results in the page


outResults.innerHTML = "<pre>" & Server.HtmlEncode(strXMLResult) &
"<pre>"

End Sub
</script>
<!-----------------------------------------------------------------
---------->

</body>
</html>

7 P4 7 P" 

: 
ASP.NET ! >

:   
.,
++ 8
   $      $

:!"
 > 1  ,
 . *; !? .  W + W  ! > % +  $ 0 U > U 
Windows  IIS ! > 1  ; ASP.NET *=

Universal Knowledge Solutions s.a.l 217


:  # $%&
:(,8 *# 0. !  9 
>  .# •
Windows  IIS !     $ •
Windows  IIS ! 5 $ +$ •

ASP.NET  > 5A


4 •

ASP.NET 52 9

!  W, 58- + 0 . W I2   4 *   5 & (,8 5$# ,T2   B

.5 & (,8 + I2  $# I2 (4 * 1  = IG  ,72 ASP.NET

(4 * $ (4 P$ @ *7 *  (, ., %  T 5$# *


(4 <W P$ +
. X    5$# (4 * $ 2  ,
 T , *+ 1@

:    B$4   (ASP)   ! 5$# G  ,8 5+ <8
  2 1@ (4 * , '  2 X A=4 •
(4 *   + 0   $ Windows  IIS ! > W (,8 8& •
  2 5,
 2 5$#

4 1   > 5  (,8 X$ K $ .NET 4 ! ,8 ASP.NET ! 5$# +
* ! +$ ! 5 , 1 
  +  'W = !    % 
 .#
.ASP.NET 1 <  *,  3, (,8 +  

9  %

:  W 1   2 (,8 %< 8 > +

Universal Knowledge Solutions s.a.l 218


    $ •
5 $ 5 $; •
* 7 •
5  2 2 !# X > •

:  W 1   2 (,8 %< 8 > +

: (  : 
  \  .!8^  C2 57 C,
  *+  .      !  , !.
  <T > I
 .C ,8 9  (,8 @ + 2
X   (4 *
.5 v @ ($ 2  +0 @ 2  @ % = 2  ,+ *

: 4  .


I
 .#,  , C 5 $ C +4 G=  @ 0 1   .    
*  (, .(ACL)  T (4 *  $ W+    8
   , /0.
$ 3, = 0. +  X $ ASP $# (4 * => $2 , 04 :*7
.$# 3, ,
 IIS 6 ' 2 *@ $# /0. %A @

: 8 
F *7 *  (, . H =  . 5$ H    * C2 (,8 * 7 9_ R
$ ! I
> + 1 
 (,8 $# 3, ($ 5$# 1 
1     $  H
*> $ + (Anonymous) *
 2 (Guest) 9  1   $  % >
.IWAM_%machinename% !7 $  IUSER_%machinename% 
1@ 1 
! 5,
 1 
(4 < H  4 I
 IIS  8 5$ /0. 
 I

+  1 
  IIS !   (4  = T * $ 0[ . (,8
8    (4 * '  I0 %IUSER_%machinename $ *;  $
.
 I
 COM+ 2 COM 5+  $# C 4 *    + 04 2
Universal Knowledge Solutions s.a.l 219
.9 _  T  8   IWAN_machinename $
 .aspx *= !.   5#,+ ^  3, (,8 ASP.NET ! 5#, (4 * +$ 
9, (4    B 2    5 5#, (4 4 .cs  .vb  .cx  .ax
K $ pdf zip doc 5#,  *7 5#, (4 * 8@ & . ASPNET_isapi.dll
.ACL *7    Windows 5   5#, /0.  $ +$ I

:
 & & 5 - 9
.V   %  f  * ?= X K $+ !W  # ( X G  ,8 

ASP.NET 52 9

 ASP.NET ! 58-   5+ !   ,    5@ #  <  +0
 #  5, *   I0 web.config 9,     ,8 2  2  ASP  #,
. (MMC ) ISM 5 - 5  
  .84 + !

 L5   58- +L C>  IIS !  > 584 ( *$ I2 (,8
(4 C, $   , IIS , 04 ASP.NET 1  > 5 ,8 5,  IIS *
Application %0 ' *;  3, * $  , , 58-  J + . ASP.NET
: Configuration

Universal Knowledge Solutions s.a.l 220


,
 ! aspnet_isapi.dll 9, (4 % .X 5$; * ! 5, 1 
* $  C2 X$;
.NET *8 [ 

: $# , !  ' *+= !,  

*+= 

Request ,
User’s IP Address or domain *
 8 2  8 *.
Permitted access?
j*
Anonymous Access Enabled? j   *
 * 'R *.

Universal Knowledge Solutions s.a.l 221


Execute under $ 5$ * ?=
IUSR_%machinename% account
IUSR_%machinename%
Denied U
Send Resource to Client  (4   * 4
Authenticate user via Windows (,8 <8   .  $
2000
Windows 2000
Authenticated     $ B

Performing ASP.Net Related 6  > 5A


4 0 #
Security checks
ASP.NET
Yes 
No ;+

Windows2000 ! 5 $;

(,8 #,  (4 *   'R 0   W Windows 2000 X#$
. +$+ * H 
(,8 2 C# 
 (,8 X#$ W /0. + 2 + .


Active %2 *;  2 ComputerManagement %2   8 W /0  +$ I



. +$ 52  Directory Users

: " 4 )

Universal Knowledge Solutions s.a.l 222


5 $;   % + 8
 1  T *$ ! A  58
 
/0. ? (4  &    (4 *,  500 5 $; 84 8 < . =
5 $; 8
 /0. A84 8
 A=4 !#+ . ? I2 , 8   4 %  5 $;
5 $; ? !#+ 5 $; 3, (,8 ? I2 2  *$ ! .$  (,8 ,
. 4  0  *+ (,8 7J 8
 
Users  GroupTest 8
 ! 8    %0 '

IIS 52 (  : 

 > $  ,8 A


4 , ; IIS        ,   8
: ,  (4 * C$ *@ 5 &  8
  + C ,8

::   IP  


"
6  \ W,  A2 2 IP 8   NT  Windows 2000 Server ! +
6   IP Address and Domain Name 
  30  .#,   (4 *
.IIS   1@  Properties %0 ! Directory Security
.   %$ 8
 2 8  1@ (4 W %  * !  , /0. 8

: " 4 $ #  =  (7 " 4


. 1@ *
2    I
  @ 5 =  8- Properties %0  < 2 +
 5 = 1 F 2  @  5 = /0  + .SSL  ] *& * # + 30+
. (4 * *$ I0 
 (,8 9 ,  9 

IIS 52 (  :  L  

    $    $  '   


 Directory Security  %0 ! X$;
. 
!

:  W 5    2 Authentication Methods %0 

Universal Knowledge Solutions s.a.l 223


$ C
$
 *$ ! WWW  (4 *  I> + K $  4 

 8   * .8 IIS  .      2 C  IP 8
.IWAM 2 IUSER $ *

*
 %0   I
.  * * # A?4 8 :5449 ( 
" " 4

.8 . IIS (4   4  ,+   #=  K $ .  *@  , *
3, !  (,8 , *  $ '  Windows ! $ 8 K$ IIS 
& 30 +  <H   64bit (,8 !  #= 2 X$;   & . 4 *  $2
. 8 2 
 P$ ! 5  ! <   0. 

A?4  04 :(Digest) " 0;  7 #  ) 4 ; :  (  : 
   .  ,+   5, , %0  X4 I
  * * #
 (4 . #=    4  
 (,8  B 2 5, 1 5, /0. 1

7 /  . #=   5, /0.  C  3, 1 .($ /
 #= 1 )
      /0. * ..J=4  !   (4 *     
2 , + 5+ 
$ !  +[ 2 ($   + .NET 5  5 IE 5 &
' $  0. 3,    (4 * , ' R  04 H !.    

.$   (4 * 5 $; $ 0  +  Windows (,8

  ,  =   %8 Windows  :Windows Y


!" ( : " 4
/0. 2 ! !>  # NTLM *+   2 Kerberos *7 #= *+  8 30
.* + , 2  
9,   2 + &  , /0. > 5 & (,8 *, W; T  
   $ IIS *  B > 5   *+ * #    *, * # A?4  *$ !
+ *$ ! 2 *$+ !>    $ 7 Digest      $ 7 Windows 6 
. 7 (>   8 & 

$ ! C   $  $ Authentication Methods  %0  +
  *
Universal Knowledge Solutions s.a.l 224
Universal Knowledge Solutions s.a.l 225
.Request.ClientCertificateCollection  <
  C# B$ (4 * +

.Users 8
 (4 (4 < H 5$ 1 
4 I


! TestGroup % 
 8
 (4 4 < W, %  58
 1 
! *+= ! X$;
. W=[ @

Universal Knowledge Solutions s.a.l 226


Windows 2000 52  4

 $ 3, & !  (4 *    I2 +     .  $ 
 *+  ACL * +$ W@ ! %< 8 5 $ 5,   . 4 *
.  
 ,$ 5,
 5#, (,8 5 $ % 4  + ;
< 7 :  % W /0. % 4 +
. +=

! 5 $ 58


 5$   '  Security   Property %0 
.,
 2 9, (4 * !   *+  +,
 9, +  13 * *
   7+2 * # +$, %0  X4 Advanced   +
(,8  5 $ A> 5,
 K  +$  +4 1.90$/+/%A  5 $;
.A> 5,


Universal Knowledge Solutions s.a.l 227


IIS 52  4

8     (4 *  C+   (,8 * 5 $  $ ! < 2 IIS *
 B 2   (,8 $ +  /$ H $ I2 2 (IUSER) $ * 
.C 4 *  I0   *# 2 + I0

(,8 + 5 , /2 *+= ! .X Home Directory   ! A
 ! X
. 
   * ?=/+/%A @ ,
 2 1@

Universal Knowledge Solutions s.a.l 228


1@ 2 ,
 (,8 <8      Windows   ! 3, 8 ,# 5 $ /0. +
.IIS 5 $ 1 Windows .$ ! 5 $ * 04  4  $   

ASP.NET 52 9 F );

/0.   9 + B  IIS 2 * ?= X G , 5 >  8
   
.ASP.NET ! %  > 5  1 

. +2 * # ASP.NET ! > 5A


4 ! *+= '

Universal Knowledge Solutions s.a.l 229


*+= 

Request ,
IP and Domain checked   IP
O uthenticate User
A   .  $
ASP.NET receives request ,ASP.NET ,
Is impersonation enabled? j* 7 \  *.
Run under user account (or IUser 5$ 2 )  $  5$ *
account)
$ IUSER(
Check windows ACLs on +$ W@ ! 5 $  $
resource for permission
*Windows  (,8
Run under local system account X  !,$ $  *
Performing ASP.Net Related 6  > 5A
4 0 #
Security checks
ASP.NET
Denied U
Send Resource to Client  (4   * 4
Yes 

Universal Knowledge Solutions s.a.l 230


No ;+

ASP.NET 52 9 F );

:ASP.NET 52  8 

.* 7 & <   + 04    ! ASP.NET  (> % ,
0#   , + 04     0 %   1 IIS ! * 7  # C=  # +
+$ + .  5,, ASP.NET C  $ 5 $; 2  5 $;
.machine.config 58- 9,  <ProcessModel>  *;  < ,  $
.“AutoGenerate”  ,+ + “machine” . !W,   +

ASP.NET ! ;
< # * 7 + 04 €
 $  , 1 *  IIS ! ;
< #    * + 04 o
. IUSER_%machinename% . IIS !   *
$ (,8 <8 , 1 *  .8 IIS ! *# T   * + 04 o
. , *    Windows
I
K $  *@   ,  !  , ACL W@  $  $ ;+ ! o
.  0. 1 * '  $ + 04   (4 * \

:ASP.NET ! *# T * 7 + 04 €


A
-  $  , 1 *  *#   * + 04 o
ASP.NETO)
Windows $ (,8 <8 , 1 *  *# T   * + 04 o
. , *   
I
K $  *@   ,  !  , ACL W@  $  $ ;+ ! o
.  0. 1 * '  $ + 04   (4 * \

Universal Knowledge Solutions s.a.l 231


ASP.NET 52 9   "

+ .  5  !  *   >   5    8
 ASP.NET 
. , 0
 ,
  
 web.config 9,  5   /0. *+ 

    $ 1 * 1  (,8 +  30 9, 0.   # +   < @
.5 $

: 4 ( : &


*+   IIS (,8  8& + + .5 $    $  U2 7;7 Asp.Net 
: !. 5   .*
$ 4 
 IIS *@      $     $
Windo
< % +0   
ws
(Basic,Digest,Windows) Windows
    $     0.  Passpo !    $
.5 +  + =   !  +  rt (,8Passport
 $   ! 5, C
 
.HTML P0 (4  ,   .
<  3,  =   /0.
. 9WX ,T2    +ASP !
.NET *8 4  A
+     $
  5,  * R Forms B (,8
 . *    .   ,+ P0
. C, I$ ++ A=4 
1   $; 5, * 4 
   K $ ++ 5,
. 0. (,8   5$# 9 
2 +   W,   !. /0. None     $
Universal Knowledge Solutions s.a.l 232
* +$ + < 2 * 7  ! !W,IIS
 .IIS ! %$   <  (
$   (4 *
 2 A
-  ASPNET
.* 7 * # *$ ! IUSER $

ASP.NET 52 9   "

9, ! <authentication>   ,


 2   ,     $ U  $ 
:!, + ,
 2 1@ 0  web.config

<configuration>
...
<system.web>
<authentication mode="Windows|Passport|Forms|None">
authentication options used for the application
</authentication>
<authorization>
users and roles that have access to the application
</authorization>
<identity>
if application should run under a different account
</identity>
</system.web>
...
</configuration>

. web.config 9,  <system.web>       0,  ]  


& 2 1  ! 58
   $ *>  R .<identity> <authorization>
.& 2 *# * 7 + 04    $ !7 SQR  .  (4 * 1 

ASP.NET 52 9   "

: Windows     :  " 4


*, 
$ 0   $ < + ! 5  2 5 4 5  U 0. 
.5  /0. (,8 * T  , Windows $ 84 %   30  4

Universal Knowledge Solutions s.a.l 233


:*+= (,8 web.config 9,  U /0.  84 
<configuration>
...
<system.web>
<authentication mode="Windows" />
<identity impersonate="true" />
</system.web>
</configuration>

:)  " 4  


  30   (4 * $   ! 58
  W@  $ +
:*+= 30 <deny> <allow> 8  , ! <authorization>
<allow roles="comma-separated list of Windows account group names"
users="comma-separated list of Windows user account names"
verb="GET|POST|HEAD"
/>
<deny roles="comma-separated list of Windows account group names"
users="comma-separated list of Windows user account names"
verb="GET|POST|HEAD"
/>

.   +  < 2 3.


.*> 2 58
 2  1 
8 , (*)  
+ & )   * & IIS 84  $ /0. !   * 8 , (j)  
(.Users # ! &4   0. 

 
4 *$ ! ($   *#> (4 (,8>  <deny> <allow> 8 , 
 
. *2 (,8 *$, 

. <allow>  (,8  > <deny>  (F


:8
<configuration>
...
<system.web>
<authorization>
<allow roles="MyDomainName\SalesDept"
users="MyDomainName\sami,MyMachineName\adel" />
<deny users="*" />
</authorization>
</system.web>
...
</configuration>

Universal Knowledge Solutions s.a.l 234


1 
(4 4 adel !,$ $ MyDomainName  sami $, ! 9, ' 9
.  !@
$    (4 * SalesDep 8
  

HTTP 52    

* HTTP  *  +$ <deny> <allow> 8  < 2 +
:! *7 ! + Verb #
<configuration>
...
<system.web>
<authorization>
<allow verb="GET" users="*" />
<allow verb="POST" users="MyDomainName\marthasmith" />
<deny verb="POST" users="*" />
</authorization>
</system.web>
...
</configuration>

9, #  9, 2 !8  ,


  7+> * 5 $ 8[ T  *$ ! 2
:*7 ! + 30 <location>   web.config
<configuration>
...
<system.web> <!-- default for this application -->
<authorization>
<allow verb="GET" users="*" />
<allow verb="POST" users="MyDomainName\marthasmith" />
<deny verb="POST" users="*" />
</authorization>
</system.web>
<location path="mypage.aspx"> <!-- only applies to this file -->
<system.web>
<authorization>
<allow verb="GET" users="*" />
<allow verb="POST" users="MyDomainName\billjones" />
<deny verb="POST" users="*" />
</authorization>
</system.web>
</location>
...
</configuration>

8 IIS *@  C $  I0 $  &


<   $ & ASP.NET C
 2 +
:!, + 30 <identity>   
<configuration>
...
Universal Knowledge Solutions s.a.l 235
<system.web>
<identity impersonate="true"
userName="MyDomainName\MyUserName
password="MyPassword" />
</system.web>
...
</configuration>

Windows " 4
(  :   IIS  Windows ;

+ ASP.Net * %  Windows 5$ (,8  “Windows”  * 2  +0
.  (4 *,   

5 $ $ 0. A8[   (4 *, C  5$ I2 ! *+= '
:

*+= 

Anonymous Access Enabled in    *
 * 'R *. !
IIS?
IISj
Using <identity  <identity
impersonate=”True”/>?
impersonate=”True”/>
Specifying an account within the   $  $ <identity>
<identity> section to run under
C *,
Universal Knowledge Solutions s.a.l 236
Set permissions for the specified $ $, 5 $ 
account
Set permissions for ASPNET A
- $ 5 $ 
process account
ASPNET
Set permissions for individual I2 % # 5$, 5 $ 
user accounts , that is accounts
included in <authorization>  !  5$
section <allow> element <authorization>  
<allow>
To grant access to anonymous T)    *
 * \,
users (not required in a secured
application) include ‘?’ in 
( H   ! ,
permission for IUSER (IIS) $  5 $ ! "j"  
account
IIS ( IUSER
The common scenario <8 = 7+> $
Yes 
No ;+

:“Windows” ( : 52 "  )4  

  X 5  K;7 W  ,+ *$ !

Universal Knowledge Solutions s.a.l 237


%0 X  (,8  $ 3, &  + *$ !     $ 

“Passport”   (  : 

 * +$, %


 H   Windows 6      $  
7+2 (,8    7+>  $ 1 @    *   $ C,+=   + ASP.NET
1 
(,8 $ # 9  !  $ *$ + .<  ?
%8 5+ 04 > 1@ 2  
#  A
5 1 
+ K $ Active Directory 1 "Forest"  2 5
.#, 5@ ! 5+  ($ J
Universal Knowledge Solutions s.a.l 238
*$ !. + . 1@  7+2 (,8     $   <, + ! $ ! *=# *$ 0. +
*7 9  1@ *  '
 *$ ! @ (4 !H *+= * \  2 04
. Hotmail

Microsoft + =  K $ “Passport”       $   , /0. 4 +


/0. 8 1@ I2 (,8   .  $,   + “Passport service” ( 
.5 & (,8 + I2  < 8 30 . 

Passport  (4 5, * [     /0. 8 1@ (,8 * *
 8
. 
 (,8 ++ 1      $  !

 (4 ++  X[     /0. 8 H 1@ (4 *  *$ 8
.C .  $  @ C2 <7 Passport

 V  5 7  /0. (,8 *$, *


  & !
 T Passport  
. /0. *8 * #   (,8

web.config 9,  0.  + 8- *


  ,8 
<configuration>
...
<system.web>
<authentication mode="Passport">
<passport redirectUrl="internal|url" />
</authentication>
</system.web>
...
</configuration>

  ! $#, !  $ $ redirectURL !. % $ # <passport>  8
(4 Passport  5 7 *@ < W,     /0. + .    $ *= *$ !  4 C

.“Internal”  

Universal Knowledge Solutions s.a.l 239


:!+  (,8 * *
 A
4 + “Passport”  * # 8
    ,   •
++  % #= @ C  +  Passport  (4 C *
 @  /0. + 04 •
  . (,8 9 , Passport  (4 *   
 * 4    $; A  *$ ! 2 ++ !  % #= @  8 *$ ! •
Passport   * *
 $# (4
* *
   •
     C8   @ 1    (4 C, $ %84  C .  $  *$ ! •
 
(,8 +++

>? 0 5
 (  : 

= < $2 )  8 >  , 


   + & ! 5&$  $  U 0. 
.(5++ (,8 ! $ P0 (,8 !     $ (4
 ,  + ! 5 ,    2 5 C2 .   /0  ,   ASP.NET !  

. (ASP)   1 * 8 <
   
* *
 ==) * *
 ==  $ *+= (,8X$,   /0    
. 0
 P0 IG   + * (Windows 

.P0   8     $ A
4 \ = ! *+= \ =

Universal Knowledge Solutions s.a.l 240


*+= 

Request ,
Authenticate and authorize user C$   .  $
5 $
Is authentication cookie present in  ++ ,     *.
header
    $
Redirect user to login form page P0 $# (4  C
 %84
* *

User Submit credentials *
 5,  *
Authenticate user   .  $
Add cookie to header ,    (4 ++ 4
Check if user is authorized to (4 * ,  $ +G
access resource
 
Send resource to client  (4   * 4
Yes 
Universal Knowledge Solutions s.a.l 241
No ;+
Fail *=
Denied U

,    A$  +G  K $ ASP.NET (4 , C


 IIS !     $  2 
.++,

0. 2 / %  T ++ 5+ 04 2 .   (4 * ,  04 ++   
 C
  & ! 5  ++  $; 2 2 <   (4 * *
  
* [     ,+ *  5,  * . * *
 P0 (4
(4 , * 4 ,    (4  4 ++ A=4   $  K $   (4 5,
. ,  (4  *  $  +G   K $   ,$ 

>? 0 5
 (  :  ;

  < 2 web.config 9,   8 P0 (,8 ! $ 84 


: *+= 30 <authentication>
<configuration>
...
<system.web>
<authentication mode="Forms">
<forms name="cookie-name"
path="cookie-path"
loginurl="url"
protection="All|None|Encryption|Validation"
timeout="number-of-minutes" >
<credentials passwordFormat="Clear|SHA1|MD5">
<user name="user-name" password="user-password" />
<user name="user-name" password="user-password" />
... more users listed here ...
</credentials>
</forms>
</authentication>
<machineKey validationKey="AutoGenerate|key"
decryptionKey="AutoGenerate|key"
validation="SHA1|MD5"/>
</system.web>
...
</configuration>

Universal Knowledge Solutions s.a.l 242


: K $
++  *7 Name 
 ++ + 8 , ( "/"  %8) C,
2   ++ + I0  *7 Path 
.1@ *+
.* *
 $# (4 *,  $ Login_url 
: ++, , > 
 $ Protection 
04 (Triple DES) #= <machinekey>  (,8 ! #=   All   o
.5  48  +2 \# * +
. #=  ; None   o
.5   $  ,8  & + ++ #=  Encryption   o
.++ #=  ,8  & 5   $  ,8  Validation o
.  $; !  ++, ; 5@ W@ $ Timeout 
!  ,+ #=  #=     $ <credentials>   + 
 $  <user> 8  8
 
4  0.  + web.config 9,
. $  (4 * (,8 
#=  ! #=   ' # $ I0 <machinekey> 8  $ < 2 + 
.++ B$

: *+=  +  0   W,  


<machineKey validationKey="AutoGenerate"
decryptionKey="AutoGenerate"
validation="SHA1" />

>? 0 5
 (  :  ;

:P0 (,8 !    $ $ ! web.config 9, C ,8    (,8 *7
<configuration>
...
<system.web>
<authentication mode="Forms">
<forms name="MyNewApp" path="/" loginUrl="/main/login.aspx"
protection="All" timeout="30" >

Universal Knowledge Solutions s.a.l 243


<credentials passwordFormat="SHA1">
<user name="billjones"
password="87F8ED9157125FFC4DA9E06A7B8011AD80A53FE1" />
<user name="marthasmith"
password="93FB8A49CC350BAEB2661FA5C5C97959BD328C50" />
<user name="joesoap"
password="5469541CA9236F939D889B2B465F9B15A09149E4" />
</credentials>
</forms>
</authentication>
<!-- keys usually only specified for a Web farm -->
<machineKey validationKey="3875f9...645a78ff"
decryptionKey="3875f9...645a78ff"
validation="SHA1" />
</system.web>
...
</configuration>

:"  )4 >? F7;


.* *
  P0 A=4 (,8 *  & web.config 9, 84 
:P0 0. *7 8   *7 !
   !,  
<%@Page Language="VB" %>
<html>
<body>
<form runat="server">
UserName: <input id="txtUsr" type="text" runat="server" /><p />
Password: <input id="txtPwd" type="password" runat="server" /><p />
<ASP:CheckBox id="chkPersist" runat="server" />
Remember my credentials<p />
<input type="submit" value="Login" runat="server"
onserverclick="DoLogin" />
<div id="outMessage" runat="server" />
</form>
</body>
</html>

!, + + !
   


Universal Knowledge Solutions s.a.l 244


>? 0 5
 (  :  ;

:"  )4  5)
 !
 

  & 04 < H A!= *+   1    +  +0   P0 (,8 !    $ +  T 
. , 5 ,  A> !
   + 

. System.Web.Security A> A (4 ASP.NET G !  ! 9# 1 


!
0.  . FormsAuthentication P0      $ 1  ( I0 9 (8 
: .2 W    8
 9

! % 3,     ,+    


Authenticate
web.config 9,
 (    $ ) , *8> 1 
AG 
redirectFormL
(4 , * 4 ,    (4  4 ++, A=4
oginPage
.;
< 2  4 * $ 5 ! $#
. P  *
  ,  ! % #= ++  SignOut
 & + ,    (4  #  % #= ++ A=4
SetAuthCookie
.  , * $

Universal Knowledge Solutions s.a.l 245


/0. .
&    (4  4  ++  @ %8[ 
GetAuthCookie
..  *@ ++,       8 % #  
(4 C
 *@   , ! $#,  $  
GetRedirectUrl
.* *
 $#

:!
   (4 !  [   /0.  + <04

Sub DoLogin(objSender As Object, objArgs As EventArgs)


If FormsAuthentication.Authenticate(txtUsr.Value, txtPwd.Value) Then
FormsAuthentication.RedirectFromLoginPage(txtUsr.Value, _
chkPersist.Checked)
Else
outMessage.InnerHtml = "<b>Invalid credentials</b> please re-enter."
End If
End Sub

>? 0 5
 (  :  ;

: #2 4) - 0  0;


. 4 /&
!    $2 ++   % 

timeout #  @  *;   ,    04  @ 30 ++  $;  W, % +
. web.config 9, ! <forms>  

*+ 1 ++ K $  9 1 .    ;T4 8 < 2 ++  $; A 4 
. $# (4 * H   $ 30 .   $ -   


  A8  .5,


  ++ (,8 A-   ASP.NET 
! .   /0. /0G I0 !7 *,    @  $  RedirectFromLoginPage
:* *
 $# (,8 checkbox +$  Checked   @  7
FormsAuthentication.RedirectFromLoginPage(username, persist-cookie)

 , '  (<8 50) <


*   $;  3, ++ A=4  True    8
.<
 * *
 (4  &

Universal Knowledge Solutions s.a.l 246


 C>  2 ,+= *+=   2 (,8 5++  7 $ 5  ,T2 
*# 30 .++ % $ %  *; 1@ (4 * 9 1 9 ! ++ 9 * 
.!8 2 , & ! 5&$ ! (4    0.   8

:SignOut    < @ ++   1  *$ I2 (,8
FormsAuthentication.SignOut()

5++  8 &


30 .  @  ++ 9=+ (,8 % @ T   /0. +
. *   50

>? 0 5
 Z  4 ;

' !  !.  $  + P0 (,8 !     $ 8 ] ($ ,+
  &4 web.config 9, (4 <authorization>  4 + . 4 * ,
 C  I$ I0 machine.config 9, ! %$  W, 5 $  
:!,  <authorization>

<authorization>
<allow users="*" />
</authorization>

web.config: 9, ! + *     8


  \, 30
<configuration>
...
<system.web>
<authorization>
<allow users="billjones,marthasmith,joesoap" verb="GET" />
<allow users="marthasmith" verb="POST" />
<deny users="?" />
</authorization>
</system.web>
...
</configuration>
<authorization>
<deny users="?" />
</authorization>

Universal Knowledge Solutions s.a.l 247


A&J. +  ($   (,8 Windows 6  ACL 5 $   $ &2

8 5$ /0.  I2   ,   5 $   Windows !   
.P0 (,8 !     $ 

   (,8 <  *     + 8 1   '


9, ! 2 H + ! 5, /0.  ;
< 7 P$ 0 web.config 9,  <credentials>
    H   .8  & Active Directory ! ($ 2 5  %8@ 2 XML
30 XML 9, ! 2 5  %8@  
 .  * *
 P0 ! , 5,
.#, 5   *&  A
 !  ,8   ! 5  

 "

2 (,8 8&  (4 * +$ (,8  +  ] ($ C ,8 ,  *;  X$&
,  5 $  +G 7    $   (,8    %  9 
. %$

 *;  * C \     $ (4   P$ ! 5&$  3. +
 !,   .IPrincipal , User    T>  8
  5 , 3, A2  .!
 
.    1  ! 5 ,

User W+  +   %&


strUserName = User.Identity.Name

IsAuthenticated   \


  @    $ +  $
blnAuthenticated = User.Identity.IsAuthenticated

     $ U  $ 


strAuthType = User.Identity.AuthenticationType

Universal Knowledge Solutions s.a.l 248


!  + 04    $ + Windows .      $ U + *$ ! 
IsInRole    %$ 8
 (4
blnResult = User.IsInRole("MyDomainName\SalesDept")

7 <
4 
: 
.W  5#,  asp.net !  5 

:   
  Glossary 6 X2

:!"
5#, 584  !   7+2 5 H 5@ +    7+ C   5   # ASP.NET 5 
.W 
  %#&  # + W  5#,   .A=4  # +   5   # (,8 9   ,
 /0. 
:  # $%&

:(,8 *# 0. !  9 


5+ *
  5  5,
 A=4  # + •
 > 5#,      •
GLOBAL.ASAX 9,   •

  %#&  # + W  5#,   •

glogal.asax 9,  ASP.NET !  5 

 9, (4 4 .asp 5#,  8


 *+= (,8 5+  2 K $  5  2 asp  58
. global.asa

+$ 8   5  ASP.NET 5$#+ B 2  52   # 0. 1  Asp.net 5@
 *@  4 .J=4  % 8 B 2 5#,  global.asax 9,  5  84 9,   
.ASP.Net !  2
5#,  global.asax 9,    .A=4  # +   5   # (,8 9   ,
 /0. 
.  %#&  # +  machine.config web.config

Universal Knowledge Solutions s.a.l 249


&
 $   

!  ,
 A=4 +[ 9 +  2  .W  +0    & 5,
  5,
!  8
. IIS !
j    (4 ,
 0. * $  9 + !  ,
   2  #  ]
X .8 Properties    ! & ,
 (,8  >   2  +
:   (4 *+= ! + ==

  !,$  $ ! Local Path   @  ,


 584  J + == 3, !
. ,
 0. (,8  5 $
* # (4 4  5   *
  %A  !. %  $ 2 /;82 ,+= $ ! ! X$;
.  0. (,8  #
  # * # + C2 X$; Application setting 6+ 9   !  *#> A
 ! 
(,8 .X *+= ! + ' %0 (,8   ? .8 Create  (,8  
.5 ? 5 7 Apply   !#+ ..  

.Remove   !#+  ! & ,


 8    # [ T  *$ ! 2

Universal Knowledge Solutions s.a.l 250


52  
ASP.NET

   *+ . 5 ,  5@ 9  IIS   5  ASP.NET 
5  3 =   I2 .B > 5@ 1 % +0 3 = &  H  B > 5@ 8 *#
. 5@   1 (<$& #  8 ,+ 5  !. ) Application  Session *7
  8 *#  7J T   ! 5  $2 *8 ! *, I2  *
 /0. *#  ,8
.5 
(4 4 .J=4 , + !   2 7;7  %8 ASP.NET  5  9G
:  5  5$#  ASP.NET !      3,
! 
 5, A$&   0
 ,
  % = 1 ,
 0. BIN
.5   
' .  ASP 1 < + I0 global.asa 9,, *  . 9, 0. Global.asax
   B (,8 30 5 ? (4  @ 4  ASP.NET ! K$d !
   0 #
.;
< +
+ . , > B (,8 <8   *+  584 A84 m+ :Web.config
I0 machine.config 9, !    58- (,8  ? 9, 0. ! 7 58N
. (,8 7 ASP.NET W  ! 5  1 
(,8  !  58- $

:   )4
A
+ 5+ *
 Bin .  ,
 ASP.NET  X 5;
 (,8 8& 8 <8
.  
 + *7 *  (,8 X   8 5+ *
 (ASP !) <   , /0. 5+
   COM+   8 2 5+ *
 REGSVR32.EXE %> &
.+$ $   - 5>   ! Component Service

<%
Dim myObject
Set myObject = Server.CreateObject("Example.DataAccess")
%>

Universal Knowledge Solutions s.a.l 251


  )4 /ASP.NET 52  

 *  ,@ *$ 5&J  8


 X   8 5+ *
  U \ 
 $ (,8 *$,  & U (4 4 * A72 5+ *  % 5
+  #,   7+2 * ?=  +4 8 1 5+ *
  (4 < ,$ *
.   7+>

 *  K $ 5 ,8  +- '2  ASP.NET !  *+= 3, *+ *$  L
.W  /0.  +    7+2 
+  f !#+  *+ .5+ *
  (4 !,$ * .NET , & L
*@  ; %  '  ASP.NET *@   $=  K $ Bin ,
 (4 1 
 ?,
. 
&4    ! ,
 5+   !    *+ Bin  $ ,
 B 
 & L
.   0 
*  +  *+ (ASP +) IIS 9 4 (4 ASP.NET ! + I2 *& P$ & L
.   (,8 *  2 +    ! 
 9, (,8
2   Bin ,
 (,8 5;   2 (,8 5   >   /0. ASP.NET ' L
 (4  2 C ,8 5, !, 2   
   A=[ <   *  I2 9=+
.30  C4   $ 5, 1 * /A 4 $ X&   *  *@  

global.asax $ : 4

:   ?  %8 0G  ASP.NET 5$# C=   global.asax 9, 1
<%@ [Directive] [attribute]=[value] %>
<Script runat="server">
[Application Event Prototypes]
</Script>

:()
0. 
 !   5 , (4 4 ASP.NET 5$# 5 , global.asax 8
:  global.asax  8 ! 5
 .2  . 9,

Universal Knowledge Solutions s.a.l 252


C global.asax   I0 I8 9  $ ' !  Application 
.   7   8 C2 (4 4
.Description  inherits . # *;  8 5  /0.
I8@ 9+ global.asax *@  C   I0 9  Inherits # $ 
. global.asax (4 W 2   4 ! %  /0.  #.9, 0.  
 *W7 1 

global.asax 9,,   9 Description # $ 
<%@ Application Description="A sample global.asax Description” %>

W8[   global.asax  C& A2 A    C


 0. + Import 
.global.asax  A# 0. 9# *+ * .G
4 + .  A> A# I$ ! 
 9, + 
Import C
 =&
. Assembly C
  /  8 *$ ! ! 
 9,
!    ! 9# (,8 I$ ! 
 9,  $ C
 0.  Assembly 
  $    K $ Name !. Assembly C
,  > # . ASP.NET  
.! 
 9,

9# (,8 I$ ! 


 9, 2 *>  04 Assembly  Import 
 9,
.C$=
! 
 9, 3. 2 Asp.NET !7    .  ,  ,

global.asax $ : 4

:5)
 !  [  
% =G  %+ global.asax ! !
   8 '   
<Script runat=’server’>

:*+= #include   ( *@  


 ) SSI  + + 
<!--#Include [File | Virtual]="Path to file" -->

8 9, (4  virtual  I 5#, X (,8 <8 9, (4  file *7 K $
.  
.global.asax 9, (4 C
 *@ 9, B$ 4 

Universal Knowledge Solutions s.a.l 253


9,  7+2   + = T  5, I$ 5#, A  $ ! %  /0.  +
.   7+2 ! global.asax

 Session *8 *
  T2 8 ' , <object> % =G  + 30+ 
%$ COM  T2 2    
 .NET 5#, A=- % =G /0.  + . Application
.CLSID 2 ProgID
:!. 5# K;7   #  + .J=4 + !  T> U2
.<object> % =G   5# /0. $2  + K $ classid  progid Class
<object id="appData" runat="server"
class="System.Data.DataSet" scope="Application"/>

9  ;
< 7 *+= I0  “appData”, & *$ 9  @ 2 ! *7 ! B 
.System.Data.DataSet
  + *. *$ % $ $ !  *$ 0. * 9 *
 ! Scope # $
. “Session”   *$ !  $ ,
 2 “Application”     *$ !  

:5)
 !  [  
% =G  %+ global.asax ! !
   8 '   
<Script runat=’server’>

#include   ( *@  


 ) SSI  + + 
Application  Session *8 *
  T2 8 ' , <object> % =G  + 30+

ASP.NET 52 C (  

. XML       5#, !. ASP.NET ! W  5#,


.   (,8 ,
 I2 ! X 2 5#, /0  + . web.config & 5#, /0. (
.,
 0.  A> 5,
 *+  C $ I0 ,
 (,8 C84 web.config 9, *+ 
.  A> 5,
, 58-  * 2 A> 5,
 ! 58N +
5#,  .
    5  1 
(,8  ! 58- 0
 W  9, $
.C# ,
, W 

Universal Knowledge Solutions s.a.l 254


 2$2 2  +G, web.config 5#, = * 1 K $ IIS 8[ ASP.NET 
.  $ 3, & + 04  ,   4 * 1 
!   $  58- + 2 + *7 *  (,8
web.config 5#,   http://myServer/myApplication/mydir/page.aspx
:!  
machine.config & 9, (,8 , !> W  9, 58-

C:\WinNT\Microsoft.NET\Framework\v.1.00\config\machine.config

0
 1@,  9, 0. 
  wwwroot:9, ! %
 5,
C:\inetpub\wwwroot\web.config
:9,      .
 + ! 
D:\MyApplication\web.config

9,      ,


  .
  2 + ! 
D:\MyApplication\MyDir\web.config
1 
(,8 C84     1@, 0
 ,
 ! web.config 9, 
 04
.1@ 0.  5 

. XML       5#, !. ASP.NET ! W  5#,


.   (,8 ,
 I2 ! X 2 5#, C  + . web.config & 5#, /0. (
.,
 0.  A> 5,
 *+  C $ I0 ,
 (,8 C84 web.config 9, *+ 
.  A> 5,
, 5 8-  * 2 A> 5,
 ! 58N +

5#,  .


    5  1 
(,8  ! 58- 0
 W  9, $
.C# ,
, W 
6 2$2 2  +G, web.config 5#, = * 1 K $ IIS 8[ ASP.NET 
.  $ 3, & + 04  ,   4 * 1 

Universal Knowledge Solutions s.a.l 255


C (  4=& )#  C (  4=&

   XML 5#, 5+ A$ C+ XML   9, . web.config 9, [  +0 +
. 5      5 =G     
.< W, 30 X 9=+ K $ Unicode 2 Utf-8 2ANSI 9,    + 2 +
*+= 9, 0. B$ 0G K $ <configuration> % =G . Web.config 9, 0
 
<configuration>
<!- Configuration settings would go here. -->
</configuration>
.   U2 K;7 (,8 <configuration> % =G I$
W  @2 5
 8 5$  •
W  @2 58
 •
W  @2 584 •

: C (  4=& )#
58- 2 9,   ,   web.config 9,  5  I2 ASP.NET 1 &
@2 5
 (4 web.config 9, 5  
 * +  30 8 <8 .C 8
   
  ! .NET *8 4  9# !.   W 
. IConfigurationSectionHandler
7   K $ machine.config !> 9,  *@> (,8 9 0. 8 '    &
. 8 # 5,
 1 
! 9 0. 8
+ <configSection> % =G  web.config 9,  5
 /0. 8 '  
. @> 58
    58
  @>    2
9 8 * 7 (4 4 W  5, I$ web.config 9, ! @ *+
.C
   IConfigurationSectionHandler

C (  4=& )#  C (  4=&

: C (  4=& )
% =G X 2 + .    X  T> @d   .   1 
  +4 ASP.NET 
.B 2<sectionGroup> % =G  2 <configSections> % =G  <SectionGroup>
. <system.web> @> 8
  @> 5
 1 
X *7 *  (,8
Universal Knowledge Solutions s.a.l 256
: C (  4=&
. @> 5 =G  W   58- 1
$ <httpModules> % =G *7 *  (,8 . @ *+ 9  @ V 
   &
9 (  . HTTP*   5$  58-
 B$ #  ,8 System.Configuration.HttpModulesConfigurationHandler
. <httpModules> % =G
. 8
 # #   V + 2
C2 . X$;

.(% ? % +) 9 $>  $ 5 =G, A> G /&   & 30+
:8
<configuration>

<configSections>
<sectionGroup name="system.web">
<section
name="httpModules"
type="System.Web.Configuration.HttpModulesConfigurationHandler,System.Web"
/>
</sectionGroup>
</configSections>

<system.web>
<httpModules>
<add
name="CookielessSession"
type="System.Web.SessionState.CookielessSessionModule,System.Web"
/>
<add
name="OutputCache"
type="System.Web.Caching.OutputCacheModule,System.Web"
/>
<add
name="Session"
type="System.Web.SessionState.SessionStateModule,System.Web"
/>
<add
name="WindowsAuthentication"
type="System.Web.Security.WindowsAuthenticationModule,System.Web"
/>
<add
name="FormsAuthentication"
type="System.Web.Security.FormsAuthenticationModule,System.Web"
/>
<add
Universal Knowledge Solutions s.a.l 257
name="PassportAuthentication"
type="System.Web.Security.PassportAuthenticationModule,System.Web"
/>
<add
name="UrlAuthorization"
type="System.Web.Security.UrlAuthorizationModule,System.Web"
/>
<add
name="FileAuthorization"
type="System.Web.Security.FileAuthorizationModule,System.Web"
/>
</httpModules>
</system.web>

</configuration>

: C (  4=& )
% =G X 2 + .    X  T> @d   .   1 
  +4 ASP.NET 
.B 2<sectionGroup> % =G  2 <configSections> % =G  <SectionGroup>
. <system.web> @> 8
  @> 5
 1 
X *7 *  (,8

: C (  4=&
. @> 5 =G  W   58- 1
$ <httpModules> % =G *7 *  (,8 . @ *+ 9  @ V 
   &
9 (  . HTTP*   5$  58-
 B$ #  ,8 System.Configuration.HttpModulesConfigurationHandler
. <httpModules> % =G
. 8
 # #   V + 2
C2 . X$;

. 9 $>  $ 5 =G, A> G /&   & 30+

4  <= " 4


1 
 C  
 I0 ,
 (4 W   58- 1 
K  !W, *+=   +0 +
.C  8 # 5,

% =G  !$ W  9,   !8    584   +
. path # 1 <location>
5,
  584   + machine.config . !$ W  9, + *$ !
Universal Knowledge Solutions s.a.l 258
  9, 58-  3+    web.config 5#, !  .5  2   &
.  2 !  ,
  ,

: 8
<configuration>

<location path="EnglishPages">
<system.web>
<globalization
requestEncoding="iso-8859-1"
responseEncoding="iso-8859-1"
/>
</system.web>
</location>

<location path="EnglishPages/OneJapanesePage.aspx">
<system.web>
<globalization
requestEncoding="Shift-JIS"
responseEncoding="Shift-JIS"
/>
</system.web>
</location>

</configuration>

: C (  ; =;
  2 584  $ + <location> % =G   584  $ (4 -
. H 9,  W  584  9, 0. ! %$ W  584 /0. ?  & K $
(4     %$ 1@ (,8 allowOverride #  + 584 8
 *#@-
.false
. #,   * 7 584 *#@[ W    ! *7 !
<configuration>

<location path="app1" allowOverride="false">


<system.web>
<identity impersonate="false" userName="app1" password="app1pw" />
</system.web>
</location>

<location path="app2" allowOverride="false">


<system.web>
<identity impersonate="false" userName="app2" password="app2pw" />
</system.web>
</location>
Universal Knowledge Solutions s.a.l 259
</configuration>

: *+=  9, W  9,  / ?  8- 0. 


 $ 8
<configuration>

<system.web>
<identity userName="developer" password="loginpw" />
</system.web>

</configuration>
.G  X   9

1 
 C  
 I0 ,
 (4 W   58- 1 
K  !W, *+=   +0 +
.C  8 # 5,

% =G  !$ W  9,   !8    584   +
. path # 1 <location>
5,
  584   + machine.config . !$ W  9, + *$ !
  9, 58-  3+    web.config 5#, !  .5  2   &
.  2 !  ,
  ,

: C (  ; =;
  2 584  $ + <location> % =G   584  $ (4 -
. H 9,  W  584  9, 0. ! %$ W  584 /0. ?  & K $
(4     %$ 1@ (,8 allowOverride #  + 584 8
 *#@-
.false

ASP.NET Y C (  $ 52 4  4=9

5#,  W  584 


  !    @> 5
  8
 3.
.  *+ 9     @>  ! *
 . web.config

9  


http6   5$  58-  8 *J  0. <httpModules>
1 

  ,8 ! 3 = 5$ /0. 2 K $ .  

Universal Knowledge Solutions s.a.l 260


 > !$ W= 5&  .  (4 
 5,
.* *
 5 ,8
. IHttpHandler 9# (4 %  5$ 8 *J  0. <httpHandlers>
< 2 *J  0. 2 +  58- /0.  8 # 5,
 K  &
9# (4  URL 5$ C
 8
.IHttpHandlerFactory
,
 $    %$ 584 8 *J  0. <sessionState>
.!,$       58- 8 *J  0. <globalization>
.ASP.NET !  
 584 8 *J  0. <compilation>
ASP.NET ! 1  584 8 *J  0. <trace>
X ! ASP.NET  W
- P0 584 8 *J  0. <processModel>
IIS  
  5 @ + 58[ +$ 8 *J  0. <browserCaps>

C (  # ) 4

(4 % = *     W  584 (4 * , Asp.NET '
. (API)    
     5;  2 8-
Browser   <browserCap> W  @ (4 *  $#  ! *7
. System.Web.HttpRequest 9,

<%@ Page Language="VB" %>

<html>
<body style="font: 10pt verdana">

<h3>Retrieving Browser Capabilities</h3>

Boolean ActiveXControls = <%=Request.Browser.ActiveXControls.ToString()%><br>


Boolean AOL = <%=Request.Browser.AOL.ToString()%><br>
Boolean BackgroundSounds = <%=Request.Browser.BackgroundSounds.ToString()%><br>
Boolean Beta = <%=Request.Browser.Beta.ToString()%><br>
String Browser = <%=Request.Browser.Browser%><br>
Boolean CDF = <%=Request.Browser.CDF.ToString()%><br>
Boolean Cookies = <%=Request.Browser.Cookies.ToString()%><br>
Boolean Crawler = <%=Request.Browser.Crawler.ToString()%><br>

Universal Knowledge Solutions s.a.l 261


Boolean Frames = <%=Request.Browser.Frames.ToString()%><br>
Boolean JavaApplets = <%=Request.Browser.JavaApplets.ToString()%><br>
Boolean JavaScript = <%=Request.Browser.JavaScript.ToString()%><br>
Int32 MajorVersion = <%=Request.Browser.MajorVersion.ToString()%><br>
Double MinorVersion = <%=Request.Browser.MinorVersion.ToString()%><br>
String Platform = <%=Request.Browser.Platform%><br>
Boolean Tables = <%=Request.Browser.Tables.ToString()%><br>
String Type = <%=Request.Browser.Type%><br>
Boolean VBScript = <%=Request.Browser.VBScript.ToString()%><br>
String Version = <%=Request.Browser.Version%><br>
Boolean Win16 = <%=Request.Browser.Win16.ToString()%><br>
Boolean Win32 = <%=Request.Browser.Win32.ToString()%><br>

</body>
</html>

 W  584 (4 *  1    /0  *  +4 (4 -
.W  ! @ I2  5  %  System.ConfigurationSetting 9
V (,8  ConfigurationSettings  C84  I0  ? 2 . X$;

.  0   
. <customConfig> , W  5  (4 *  # + ' ! *7
 1 CustomConfigSettings    T   9  V 2 7  #
Enabled

Dim config As CustomConfigSettings = CType(ConfigurationSettings("customconfig"),


CustomConfigSettings)

If config.Enabled = True Then


' Do something here.
End If

:
 ; " 4

*75 ,  58- X#$ . W  5#,  .2 7+> 5& $2 + @
  5  %8 *& 5,   9   9 $ ,,  58-
.f4... XML 5#, 1@ 5#, 5 
I0 <appSetting>  (machine.config 9,  %$) < W,   @> 
. ( @/) 5 W7 *+= (,8 58-  C +
.  5  %8 * 9  I0 <appSettings>  ! *7 X
Universal Knowledge Solutions s.a.l 262
<configuration>
<appSettings>
<add key="pubs" value="server=(local)\NetSDK;database=pubs;Trusted_Connection=yes" />
<add key="northwind"
value="server=(local)\NetSDK;database=northwind;Trusted_Connection=yes" />
</appSettings>
</configuration>

.W  584 9, ! X#$    C  %#&  ! $#, !
   !,   
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>

<html>

<script language="VB" runat="server">

Sub Page_Load(Src As Object, E As EventArgs)

Dim dsn As String = ConfigurationSettings.AppSettings("pubs")

Dim MyConnection As SqlConnection


Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection(dsn)


MyCommand = New SqlDataAdapter("select * from Authors", MyConnection)

Dim DS As New DataSet


MyCommand.Fill(DS, "Authors")

MyDataGrid.DataSource= New DataView(DS.Tables(0))


MyDataGrid.DataBind()
End Sub

</script>

<body>

<h3><font face="Verdana">Retrieving Configuration Data</font></h3>

<ASP:DataGrid id="MyDataGrid" runat="server"


BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"

Universal Knowledge Solutions s.a.l 263


Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/>

</body>
</html>

:   W  584  @ (4 *  *7 ! X$; +


Dim dsn As String = ConfigurationSettings.AppSettings("pubs")

________________________________________________________________________________
9 F*) – 7 8 

: 
ASP.NET ! A 
:   
5  A   !W
 A   P  A    $;  A   A 

:!"
   /0.  ASP.NET 5# .A> 1  5&
  7+ ! ,     5 ]  A  
. &    8
 5@
.    # +    /0. (,8 9  ,
 /0. *; *$

:  # $%&
:(,8 *# 0. !  9 
MC@   A   # •

P  A  •
!W
 A  •

5  A  •

: "
ASP.NET ! A 

Universal Knowledge Solutions s.a.l 264


F"  

 ! 5  (,8 X$ 30 A> 1  $ *


 !  %  A  5  F
( 4 *,    7+ 3,  ! )   #,+ 50 5 2  + *+=  4 *
.% +0 
5, 8 5  2 5$# (,8 *$,  5  *
 ! A   HTTP %84 
. ,8 *$ 2 .A=4 %84 A8  5  /0. 

ASP.NET:  5  !   + ! A   U2 K;7

M , . !  +   5


& A   K $ : P  A  €
M , . ! 
&  A
A   K $ : !W
 A  €
. <
  %$  T2 A   K $ : 5  A  €

   ,8 + ! 1@ (, .$# *+ A  ! + ! 5&$ ! < # P  A  +


7+   + K $ .A> ! + $ ! <  @   $# A   ,8 + !8 ,
. .G=2 I0  0 #  % = $# /0  5, 

     , ;
< 7 $# 
$  –< ,8 $# *+ A  + &  $>  !
#,+ P$ ! 5  2  T> (,8 $# ! 9  I
  + $ /0. ! . , *+
+ + .   %$ %  W  .J=4 + .8 . W   $  W=-  8 (
)
.$# P   1 Z !W
 Z   F 2

:F" *
.  .> ? 5   $2 < 2 A    $ 
.$ 5@ 5   $;  $ 2 X   *# 5  K $  2 +
A  *$ ! A    4 $  $; A    A84  $ /0. !
.C $;

Universal Knowledge Solutions s.a.l 265


! , , 
  $ A  5, (4 * *$ I0 !
   
.
$ $  W=4 %84  .  8 *$ !  .A 

! A  8 ASP.NET 8 A=4   m+ *+= A  \# 2 9, U  5$,
8  $; A -   /0.  K $ H A  8 (,8 2 !
 9, (,8  A 
.( H 8 2 9,)     ! ? I2 (,8 <8

 > " F"

I0 B$, A  A
[ 
/ ,  ,, 
& %  ! # 5  $2 P  A  
. +   5$#  /  

 , I> 
 I2 A    < ,8 +  Asp.NET ! < W, *_ #R P  A    +
.A , ,@ 
& *
 ' A
4 0 

(,8 (4   @ (4 4 A    $;   +;   & A , ,@  
 *

.A  (4 *

:   B$4   , /0. 4 +


(B #  ) OutPutCache API €
(B  8  ).@OutPutCach C
 €

.$#, GET   , *2 B P  A   @ A=4  P  A  * # 8


P  A   $# /0. (,8   (HEAD 2 GET  ) 5, 1 
   0. 
.A  5,  $; A  $

A  !  $# + 0[ . $#   $  A & 5  +0 + P  A  1
  @ 60 A  $# 4   A      @ 60 A &   $   P 
.P  A 

Universal Knowledge Solutions s.a.l 266


.8 +  $# (,8 !
   0 # %84   5 @ 0.  H , *  *$ !
. ,  $; A    $; A    0. (,8 , . 
 $# A 

C
  P  A      ! *7 ' @OutPutCache  X K $
.C  
&    I0
C
,  X$;@outPutCache #  @  $ (4 4  7 60 * A  % 
VaryByParam   (4 “non” + A    $ 9,  $# 2 (
GET 2 POST.

<%@ OutputCache Duration="60" VaryByParam="none" %>


<html>
<script language="VB" runat="server">

Sub Page_Load(Src As Object, E As EventArgs)


TimeMsg.Text = DateTime.Now.ToString("G")
End Sub

</script>

<body>

<h3><font face="Verdana">Using the Output Cache</font></h3>

<p><i>Last generated on:</i> <asp:label id="TimeMsg" runat="server"/>

</body>

</html>

> " F"

 ]   , A  , HTTP 5   (,8 +2 %     ! 5 ,  2
. System.Web.HttpCachePolicy 9 . !

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60))
Response.Cache.SetCacheability(HttpCacheability.Public)

$# ,    %  *+ ! A &  * .G %84 I


  U    *

SlidingExpiration   30 
Universal Knowledge Solutions s.a.l 267
Response.Cache.SetSlidingExpiration(True)

.
 %8[ <nW   (4 C
 ,   A &   8
 $; !   0[   
$ !, A    
 ! 5&$ !  A &  #
.     , 8 A?& + 5 $

:!. ASP !  5+ !     (,8 ASP.NET X$ 30+

Response.CacheControl = "Public"
Response.Expires = 60

: 8
. !$   X- Timemsg +$ 8  X$; ! *7 !
C> A   * $# 5+ 04   0. +$    # !
   0. X 
.B 2 %  $# 0 # %84  

<%@ OutputCache Duration="60" VaryByParam="state" %>


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="VB" runat="server">

Sub Page_Load(Src As Object, E As EventArgs)


Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
Dim ds As DataSet
Dim queryState As String
Dim selectCmd As String

queryState = Request.QueryString("state")
If queryState = Nothing
selectCmd = "select * from Authors"
Else
selectCmd = "select * from Authors where state = '" + queryState + "'"
End If

MyConnection = New
SqlConnection("server=(local)\NetSDK;database=pubs;Trusted_Connection=yes")
MyCommand = New SqlDataAdapter(selectCmd, MyConnection)
Universal Knowledge Solutions s.a.l 268
ds = New DataSet()
MyCommand.Fill(ds, "Authors")

MyDataGrid.DataSource=new DataView(ds.Tables(0))
MyDataGrid.DataBind()

' capture the time of the current request


' subsequent requests while we're still cached
' will show the original time
TimeMsg.Text = DateTime.Now.ToString("G")
End Sub

</script>

<body>
<h3><font face="Verdana">Using the Output Cache</font></h3>

<b>Authors by State:</b>

<table cellspacing="0" cellpadding="3" rules="all" style="background-


color:#AAAADD;border-color:black;border-color:black;width:700px;border-collapse:collapse;">
<tr>
<td><a href="outputcache3.aspx?state=CA">CA</a></td>
<td><a href="outputcache3.aspx?state=IN">IN</a></td>
<td><a href="outputcache3.aspx?state=KS">KS</a></td>
<td><a href="outputcache3.aspx?state=MD">MD</a></td>
<td><a href="outputcache3.aspx?state=MI">MI</a></td>
<td><a href="outputcache3.aspx?state=OR">OR</a></td>
<td><a href="outputcache3.aspx?state=TN">TN</a></td>
<td><a href="outputcache3.aspx?state=UT">UT</a></td>
</tr>
</table>

<p>

<ASP:DataGrid id="MyDataGrid" runat="server"


Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/>

<p>

<i>Last generated on:</i> <asp:label id="TimeMsg" runat="server"/>


Universal Knowledge Solutions s.a.l 269
</body>
</html>

5C*) F"

6 6  A
2 P  A      ASP.NET  ,+ $# P  A  (4 -
.!W
 A   , /0. ( . $# 5 $
6 C6 ,8 A 6 * #    +$   W   A
>  $  , 
.  (,8 A
> /0. A  !7   $  K $ @OutputCache C


<8 A  fQ  7 120 % P  A  Asp.NET (4 !  8 *7 *  (,
SelectedID  CategoryID  @ (,8

<%@ OutputCache Duration="120" VaryByParam="CategoryID;SelectedID"%>

 6 > SelectedID 2 categoryID 6  @ *+ $#   A=4 A  fQ . 
6$ !6 C6 4 *6  I0 A  2 I2 .5, 1 
  $ $ +  A  !
:9,  ,

http://localhost/mypage.aspx?categoryid=foo&selectedid=0
http://localhost/mypage.aspx?categoryid=foo&selectedid=1

#6
6 86
6 C6
6[ VaryByParam #6
6, outPutCache C6
6
 6
68 (6
64 6
6-
.VaryByControl
 +$ 8  +$ 8 9; (,8 <8 VaryByControl ! A  fQ 
 ! ( @/) 5 W7 (,8 <8 VaryByParam $ ! A  f  $ ! 
:Post 2 GET    4

<%@ OutputCache Duration="120" VaryByParam="none" VaryByControl="Category" %>

*6 # T  8 *$ ! ($ $  %  VaryByParam #    & :X$;
.5;  @ (,8 A A  fQ
Universal Knowledge Solutions s.a.l 270
5C*) F"

+$  A       W@ +$ 8   +$ 8 B$ 04
.0. W +$ 8  %    (,8 A  

+$ 8  +$ 8 9  I2 ) $#    + %  +$ 8  +


. H +$ 8 P  8 A    +$  P  A   + 30+ ( H

. W
A  58
  + A
2 A   + +  P0 %  0. 

.  +$ 8  W@  @ A   9 + ! *7 '

<%@ Register TagPrefix="Acme" TagName="Menu" Src="Menu.ascx" %>

<html>
<body>
<table>
<tr>
<td>
<Acme:Menu Category="LeftMenu" runat=server/>
</td>
<td>
<h1>Hi, the time is now: <%=Now%> </h1>
</td>
<td>
<Acme:Menu Category="RightMenu" runat=server/>
</td>
<tr>
</table>
</body>
</html>


 F"

8    T2 % X#$ 5$#  C + A  3 $ ASP.NET  •


.HTTP 5,

Universal Knowledge Solutions s.a.l 271


.% +0 ! C    %$ (,8   *+  ASP.NET ! A  + •

A=4 %84     * ?= %84    % $ % , A  % +0 % $ % + •
. 
 A  % +0

    T> 1 , '     *+= 


  
 ASP.NET  •
.A 

:! .  , /0   , >   


Cache("mykey") = myValue

:+   + A    ? %& 


myValue = Cache("mykey")
If myValue <> Null Then
DisplayData(myValue)
End If

 + *7 5 ]  8


 ASP.NET  <  7+2 9WX , ! 5 ,  2
.' #  5#, 1  A &


 F"
:8
  5  %8@ (,8 ; 0 #  K $ A  &    ! *7 X
.  % $ %  *;    !   
 A 

 @ 
 2 X $#, , *2 8 .$# *#2 !   X$; *7 0. * ?= 8
A  5, .  G *   X4   .  5     ,8 *$&

<%@ Import Namespace="System.Data" %>


<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="VB" runat="server">

Universal Knowledge Solutions s.a.l 272


Sub Page_Load(Src As Object, E As EventArgs)

Dim Source As DataView

' try to retrieve item from cache


' if it's not there, add it

Source = Cache("MyDataSet")

If Source Is Nothing

Dim MyConnection As SqlConnection


Dim MyCommand As SqlDataAdapter

MyConnection = New
SqlConnection("server=(local)\NetSDK;database=pubs;Trusted_Connection=yes")
MyCommand = New SqlDataAdapter("select * from Authors", MyConnection)

Dim ds As New DataSet


myCommand.Fill(ds, "Authors")

Source = New DataView(ds.Tables("Authors"))


Cache("MyDataSet") = Source

CacheMsg.Text = "Dataset created explicitly"


Else
cacheMsg.Text = "Dataset retrieved from cache"
End If

MyDataGrid.DataSource=Source
MyDataGrid.DataBind()
End Sub

</script>

<body>

<form method="GET" runat="server">

<h3><font face="Verdana">Caching Data</font></h3>

<ASP:DataGrid id="MyDataGrid" runat="server"


Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaad" />
Universal Knowledge Solutions s.a.l 273
<p>

<i><asp:label id="CacheMsg" runat="server"/></i>

</form>
</body>
</html>

:2 *7
.XML 9, (,8  8  X4   *7 0. !
(4  
*
 4 8  XML 9, . . 5,  +   *7,  = % +#
.A  !  A=4 %84   $#  P0  9,

<%@ Import Namespace="System.IO" %>


<%@ Import Namespace="System.Data" %>

<html>

<script language="VB" runat="server">

Sub Page_Load(Src As Object, E As EventArgs)


If Not IsPostBack
LoadData()
End If
End Sub

Sub NewAuthorBtn_Click(Src As Object, E As EventArgs)


If Not Page.IsValid
AuthorMsg.Text = "Some required fields are missing"
Else
Dim fs As FileStream
Dim reader As StreamReader
Dim ds As DataSet
Dim newAuthor As DataRow
Dim writer As TextWriter

' open the file and read the current authors


ds = New DataSet
fs = New FileStream(Server.MapPath("authors.xml"), FileMode.Open, FileAccess.Read,
FileShare.ReadWrite)
reader = New StreamReader(fs)
ds.ReadXml(reader)
fs.Close()

' append a row

Universal Knowledge Solutions s.a.l 274


Try
newAuthor = ds.Tables(0).NewRow()
newAuthor("au_id") = AuthorId.Text
newAuthor("au_lname") = LastName.Text
newAuthor("au_fname") = FirstName.Text
newAuthor("phone") = Phone.Text
newAuthor("address") = Address.Text
newAuthor("city") = City.Text
newAuthor("state") = AddressState.Text
newAuthor("zip") = PostalCode.Text
newAuthor("contract") = Contract.Checked
ds.Tables(0).Rows.Add(newAuthor)
Catch Exc As Exception
CacheMsg.Text = "Failed to create author with id = (" & AuthorId.Text & ")<br>" &
"Author already exists."
Return
End Try

' rewrite the data file


fs = New FileStream(Server.MapPath("authors.xml"), FileMode.Create,
FileAccess.ReadWrite, FileShare.ReadWrite)
writer = New StreamWriter(fs)
writer = TextWriter.Synchronized(writer)
ds.WriteXml(writer)
writer.Close()

Cache.Remove("MyData")
LoadData()
End If
End Sub

Sub RefreshBtn_Click(Src As Object, E As EventArgs)


LoadData()
End Sub

Sub LoadData
Dim Source As DataView

Source = Cache("MyData")
If Source Is Nothing
Dim ds As DataSet
Dim fs As FileStream
Dim reader As StreamReader

' read the data from the XML source


ds = New DataSet()
fs = New FileStream(Server.MapPath("authors.xml"), FileMode.Open,FileAccess.Read)
reader = New StreamReader(fs)
ds.ReadXml(reader)
fs.Close()

Universal Knowledge Solutions s.a.l 275


Source = New DataView(ds.Tables(0))

' cache it for future use


Cache.Insert("MyData", Source, New CacheDependency(Server.MapPath("authors.xml")))

' we created the data explicitly, so advertise that fact


CacheMsg.Text = "Dataset created explicitly"
Else
CacheMsg.Text = "Dataset retrieved from cache"
End If

MyDataGrid.DataSource = Source
MyDataGrid.DataBind()
End Sub

</script>

<body>

<form runat="server">

<h3><font face="Verdana">File Dependencies</font></h3>

<ASP:DataGrid id="MyDataGrid" runat="server"


Width="900"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/>

<hr>

<h3><font face="Verdana">Add New Author</font></h3>

<asp:Label ID="AuthorMsg" Text="Fill in the required fields below to add a new author"
ForeColor="red" Font-Name="Verdana" Font-Size="10" runat=server />

<p>

<table>
<tr>
<td>Author Id:</td>
<td><ASP:TextBox id=AuthorId Text="111-11-1111" runat=server/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="AuthorId" Display="Static"
ErrorMessage="*" runat=server/></td>
</tr>
Universal Knowledge Solutions s.a.l 276
<tr>
<td>Last Name:</td>
<td><ASP:TextBox id=LastName Text="Doe" runat=server/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="LastName" Display="Static"
ErrorMessage="*" runat=server/></td>
</tr>
<tr>
<td>First Name:</td>
<td><ASP:TextBox id=FirstName Text="John" runat=server/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="FirstName" Display="Static"
ErrorMessage="*" runat=server/></td>
</tr>
<tr>
<td>Phone:</td>
<td><ASP:TextBox id=Phone Text="555 555-5050" runat=server/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="Phone" Display="Static"
ErrorMessage="*" runat=server/></td>
</tr>
<tr>
<td>Address:</td>
<td><ASP:TextBox id=Address Text="One Microsoft Way" runat=server/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="Address" ErrorMessage="*"
Display="Static" runat=server/></td>
</tr>
<tr>
<td>City:</td>
<td><ASP:TextBox id=City Text="Redmond" runat=server/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="City" ErrorMessage="*"
Display="Static" runat=server/></td>
</tr>
<tr>
<td>State:</td>
<td><ASP:TextBox id=AddressState Text="WA" runat=server/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="AddressState" ErrorMessage="*"
Display="Static" runat=server/></td>
</tr>
<tr>
<td>Postal Code:</td>
<td><ASP:TextBox id=PostalCode Text="98052" runat=server/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="PostalCode" ErrorMessage="*"
Display="Static" runat=server/></td>
</tr>
<tr>
<td>Contract:</td>
<td><ASP:CheckBox id=Contract Checked runat="server"/></td>
<td></td>
</tr>
</table>

<asp:button Text="Add New Author" OnClick="NewAuthorBtn_Click" runat=server/>


<asp:button Text="Refresh List" OnClick="RefreshBtn_Click" runat=server/>
Universal Knowledge Solutions s.a.l 277
<p>

<hr>

<p>

<i><asp:label id="CacheMsg" runat="server"/></i></p>

</form>
</body>
</html>

58 F*)
: 
*8 = 

:   
*$& ,R K$> * $ K$  +2 K$   K$   A

:!"
 +    1 ! + 
 *+   *$   ,
  A
 0.   ?
. , !
   + , !$ (,8

:  # $%&
:(,8 *# 0. !  9 
!  *8 4    5,
 *;   ? 5 !  ,  V  # + •

 7 

  *$   +4 1  


 A=4 *$ *+   ,
  A
 0. *=
. VB.NE ASP.NET

  .! +&


 5  (,8 *,  9# A=4 (> ,$  *=
.9# /0. A=- VB.NET

Universal Knowledge Solutions s.a.l 278


, A> 5A   &
< 2 
Top of Form
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections

OrderList OrderItem InventoryDB 9#  Market   


A2 A 9  7
Namespace Market

Public Class InventoryDB

Public Function GetProducts(Byval categoryID as Integer) as DataTable

Dim sqlConnection1 as SqlConnection


sqlConnection1 = new
SqlConnection("server=(local)\NetSDK;database=grocertogo;Trusted_Connection=yes")

Dim sqlAdapter1 as SqlDataAdapter


sqlAdapter1 = new SqlDataAdapter("Select * from Products where categoryid=" &
CStr(categoryID), SqlConnection1)

Dim products As New Dataset


sqlAdapter1.Fill(products, "products")

Getproducts = products.Tables(0)
End Function

public Function GetProduct(productID As Integer) As DataRow

Dim SqlConnection1 As SqlConnection


SqlConnection1 = new
SqlConnection("server=(local)\NetSDK;database=grocertogo;Trusted_Connection=yes")

Dim SQLAdapter1 As SqlDataAdapter


sqlAdapter1 = new SqlDataAdapter("Select * from Products where productID=" &
CStr(productID), sqlConnection1)

Dim product As New DataSet


sqlAdapter1.Fill(product, "product")

GetProduct = product.Tables(0).Rows(0)
End Function

public Function GetProductCalories(productID As Integer) As DataTable

Dim SqlConnection1 As SqlConnection


Universal Knowledge Solutions s.a.l 279
SqlConnection1 = New
SqlConnection("server=(local)\NetSDK;database=grocertogo;Trusted_Connection=yes")

Dim SQLAdapter1 As SqlDataAdapter


sqlAdapter1 = new SqlDataAdapter("Select * from ProductDetails where productID=" &
CStr(productID), sqlConnection1)

Dim details As new DataSet


sqlAdapter1.Fill(details, "details")

GetProductCalories = details.Tables(0)
End Function
End Class

public class OrderItem

public m_ProductID As Integer


public m_Quantity As Integer
public m_Name As String
public m_Price As Double

public Sub New(ProductID As Integer, Name As String, Price As Double, Quantity As Integer)
MyBase.New
me.m_ProductID = ProductID
me.m_Quantity = Quantity
me.m_Name = Name
me.m_Price = Price
End Sub

public Readonly Property ProductID As Integer


Get
ProductID = m_ProductID
End Get
End Property

public Property Quantity As Integer


Get
Quantity = m_Quantity
End Get

Set
m_Quantity = Value
End Set
End Property

Universal Knowledge Solutions s.a.l 280


public Readonly Property Name As String
Get
Name = m_Name
End Get
End Property

public Readonly Property Price As Double


Get
Price = m_Price
End Get
End Property

public Readonly Property Total As Double


Get
Total = m_Quantity * m_Price
End Get
End Property

End Class

public class OrderList

private m_Orders As Hashtable = new Hashtable


private m_TaxRate As Double = 0.08

public Readonly Property SubTotal As Double

Get

If (m_Orders.Count = 0) then
SubTotal = 0.0
End If

Dim x as OrderItem
For Each x in m_Orders.Values
SubTotal += x.Price * x.Quantity
Next x

End Get
End Property

public Property TaxRate As Double


Get
TaxRate = m_TaxRate
End Get

Set
m_TaxRate = TaxRate
End Set
Universal Knowledge Solutions s.a.l 281
End Property

public Readonly Property Tax As Double


Get
Tax = SubTotal * m_TaxRate
End Get
End Property

public Readonly Property Total As Double


Get
Total = SubTotal * (1 + m_TaxRate)
End Get
End Property

public Readonly Property Values As ICollection


Get
Values = m_Orders.Values
End Get
End Property

' This is the Default property


public Default Readonly Property DefaultProp(name As String) As OrderItem
Get
DefaultProp = CType(m_Orders(name),OrderItem)
End Get
End Property

public Sub Add(value As OrderItem)


If Microsoft.VisualBasic.IsNothing(m_Orders(value.Name)) Then
m_Orders.Add(value.Name, value)
Else
Dim oI as OrderItem
oI = Ctype(m_Orders(value.Name), OrderItem)
oI.Quantity = oI.Quantity + 1
End If
End Sub

public Sub ClearCart()


m_Orders.Clear()
End Sub

End Class

End Namespace

Universal Knowledge Solutions s.a.l 282


*$  C orderList 8 * 7 A=- !
    global.asax 9, ! 
.A = @+ ,
 !  *@  C   ,

<%@ Import Namespace="Market" %>

<script language="VB" runat=server>

public Sub Session_Start()

If Microsoft.VisualBasic.IsNothing(Session("ShoppingCart")) Then
Session("ShoppingCart") = new Market.OrderList()
End If
End Sub

</script>

.(%$ (,8 A
*+ * #  . +   $ aspx 9, *+= ) aspx  + 2 7
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Market" %>

<html>
<head>
<title>GrocerToGo</title>
<link rel="stylesheet"href="grocerstyle.css">

<style>
div.details { background-color:ffffcc; padding-top:15; padding-bottom:20; }
div.details table { width:375; }
div.details table td { font-family:Verdana; font-size:8pt; }
</style>

<script language="VB" runat=server>

public Sub Page_Load(sender As Object, e As EventArgs)

if (Not IsPostBack) Then

ProductListing.SelectedIndex = 0

UpdateProducts()
UpdateShoppingCart()
End If
End Sub

  %  *+ ! +G  $# * $ !


   + @ 2  1 ! X$;
 $# ! 5
 W@ K $  +G, UpdateShoppingCart  UpdateProducts  

Universal Knowledge Solutions s.a.l 283


.,
  T !   A = , ! 

 8  +   


 1 *8#   K$>  !
   +  7
f4..A = , (4  -  (,8 ? 2 %  5#  W@
public Sub CategoryList_Select(sender As Object, e As EventArgs)
CurrentCategory.Text = CategoryList.Items(CategoryList.SelectedIndex).Text
UpdateProducts()
End Sub

public Sub ProductListing_Select(sender As Object, e As EventArgs)


UpdateProducts()
End Sub

public Sub AddBtn_Click(sender As Object, e As ImageClickEventArgs)


Dim productID As Integer
productID = Int32.Parse(ProductListing.DataKeys(ProductListing.SelectedIndex).ToString())

Dim market As InventoryDB


market = new InventoryDB()

Dim product As DataRow


product = market.GetProduct(productID)

Dim shoppingCart As Market.OrderList


shoppingCart = Ctype(Session("ShoppingCart"), Market.OrderList)

shoppingCart.Add(new Market.OrderItem(productID, CStr(product("ProductName")),


Double.Parse(product("UnitPrice").ToString()), 1))

UpdateShoppingCart()
End Sub

public Sub Recalculate_Click(sender As Object, e As ImageClickEventArgs)

' Obtain Shopping Cart From Session State

Dim shoppingCart As Market.OrderList


shoppingCart = Ctype(Session("ShoppingCart"), Market.OrderList)

' Iterate over items in shopping cart (update cart with current row qty textbox value

Dim i As Integer
Dim qty As HtmlInputText

for i = 0 To ShoppingCartList.Items.Count - 1
Universal Knowledge Solutions s.a.l 284
qty = Ctype(ShoppingCartList.Items(i).FindControl("Qty"), HtmlInputText)
Try
shoppingCart(CStr(ShoppingCartList.DataKeys(i))).Quantity = CInt(qty.Value)
Catch exc As Exception
End Try
Next i

UpdateShoppingCart()
End Sub

public Sub ClearCart_Click(sender As Object, e As ImageClickEventArgs)

' Obtain access to Shopping Cart From Session State

Dim shoppingCart As Market.OrderList


shoppingCart = Ctype(Session("ShoppingCart"), Market.OrderList)

' Clear Items From Shopping Cart and then Update UI

shoppingCart.ClearCart()
UpdateShoppingCart()
End Sub

:5
 W@ K $  +0 +   <   1, !
   !,  
Sub UpdateProducts()

Dim market As New InventoryDB

' Update Product Listing at Bottom of Page

Dim categoryID As Integer


categoryID = Int32.Parse(CategoryList.Items(CategoryList.SelectedIndex).Value)
ProductListing.DataSource = market.GetProducts(categoryID).DefaultView
ProductListing.DataBind()

' Update Product Information

Dim productID As Integer


productID = Int32.Parse(ProductListing.DataKeys(ProductListing.SelectedIndex).ToString())

Dim product As DataRow


product = market.GetProduct(productID)

Name.Text = product("ProductName").ToString()
SelectedProdPicture.Src = product("ImagePath").ToString()
ServingSize.Text = product("ServingSize").ToString()
Servings.Text = product("Servings").ToString()

Universal Knowledge Solutions s.a.l 285


' Update Product Calory Information

DetailsListing.DataSource = market.GetProductCalories(productID).DefaultView
DetailsListing.DataBind()
End Sub

Sub UpdateShoppingCart()

' Update Shopping Cart UI from Basket Stored in Session State

Dim shoppingCart As Market.OrderList


shoppingCart = Ctype(Session("ShoppingCart"), Market.OrderList)

SubTotal.Text = System.String.Format("{0:C}", shoppingCart.SubTotal)


Tax.Text = System.String.Format("{0:C}", shoppingCart.Tax)
Total.Text = System.String.Format("{0:C}", shoppingCart.Total)

ShoppingCartList.DataSource = shoppingCart.Values
ShoppingCartList.DataBind()
End Sub

</script>

  & W@ *7   


 +$ 8 1 $#   A
 0. ! X
. 
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">

<form runat="server">

<table cellspacing=0 cellpadding=3 bgcolor="DC6035" border=0 width="100%">


<tr>
<td align="left"><img src="images/logo.gif"></td>
<td align="right">
<a><img border=0 src="images/home.gif"></a>
</td>
</tr>
<tr>
<td align="right" class="select" colspan="2">

<b>Select Category: &nbsp;</b>

<select id="CategoryList" style="width:75" runat="server">


<option selected value="1">Milk</option>
<option value="2">Cereal</option>
<option value="3">Soda</option>
</select>

Universal Knowledge Solutions s.a.l 286


<asp:button text="Select" OnClick="CategoryList_Select" runat=server/>

</td>
</tr>
</table>

<table border=0 width=100% cellspacing=0 cellpadding=15 bgcolor="ffffcc">


<tr>

<td valign=top bgcolor=ffffcc>

<p>

<h3>
<b>Product Category: <asp:label id="CurrentCategory"
runat=server>Milk</asp:label><b>
</h3>

<table width="100%" cellpadding=0 cellspacing=0 >


<tr style="padding-left:12" >
<td align="center" style="border-style:inset;" bgcolor="EDBE7B" width=140>
<img id="SelectedProdPicture" runat=server>
</td>
<td align="center" bgcolor="ffffcc" style="padding-right:0;">

<div class="details">

<table cellpadding=1 >


<tr>
<td colspan=3>
<b><font face="Verdana" size=3><asp:label id="Name" runat=server>
</asp:label></font></b>
</td>
<td align=right>
<asp:imagebutton ImageUrl="images/addcart.gif"
OnClick="AddBtn_Click" runat=server/>
</td>
</tr>
<tr>
<td colspan=4 >
Serving Size <asp:label id="ServingSize" runat=server> </asp:label>
</td>
</tr>
<tr>
<td colspan=4>
Servings Per Container <asp:label id="Servings" runat=server>
</asp:label>
</td>
</tr>
<tr>
Universal Knowledge Solutions s.a.l 287
<td height=5 colspan=4 bgcolor="000000"></td>
</tr>
</table>

<asp:repeater id="DetailsListing" runat="server">

<ItemTemplate>
<table cellpadding=0>
<tr>
<td colspan=3>
<b><%# DataBinder.Eval(Container.DataItem, "Name") %></b>
<%# DataBinder.Eval(Container.DataItem, "Grams") %>
</td>
<td align=right>
<b><%# DataBinder.Eval(Container.DataItem, "Percent") %>%</b>
</td>
</tr>
</table>
</ItemTemplate>

<SeparatorTemplate>
<table cellpadding=0 >
<tr>
<td colspan=4 height=1 bgcolor="000000"></td>
</tr>
</table>
</SeparatorTemplate>

<FooterTemplate>
<table cellpadding=0 >
<tr>
<td colspan=4 height=5 bgcolor="000000"></td>
</tr>
</table>
</FooterTemplate>

</asp:repeater>

</div>
</td>
</tr>
</table>

<p>

<table>
<tr>
<td class="products">

<asp:datalist id="ProductListing" DataKeyField="ProductID" showheader=false


showfooter=false OnSelectedIndexChanged="ProductListing_Select" repeatdirection="horizontal"
Universal Knowledge Solutions s.a.l 288
borderwidth=0 runat="server">

<ItemTemplate>
<table>
<tr>
<td width="150">

<asp:imagebutton borderwidth=6 bordercolor="#ffffcc"


commandname="Select" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImagePath") %>'
runat=server/>

<p>

<%# DataBinder.Eval(Container.DataItem, "ProductName") %>


<br>
<%# DataBinder.Eval(Container.DataItem, "UnitPrice", "{0:C}")
%><br>
</td>
</tr>
</table>
</ItemTemplate>

<SelectedItemTemplate>
<table>
<tr>
<td width="150">

<asp:imagebutton borderwidth=6 bordercolor="red"


commandname="select" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImagePath") %>'
runat=server/>

<p>

<%# DataBinder.Eval(Container.DataItem, "ProductName")


%><br>
<%# DataBinder.Eval(Container.DataItem, "UnitPrice", "{0:C}")
%><br>
</td>
</tr>
</table>
</SelectedItemTemplate>

</asp:datalist>

</td>
</tr>
</table>

</td>

<td width="315" valign=top class="cart" bgcolor="#EDBE7B">


Universal Knowledge Solutions s.a.l 289
<h3>Your Shopping Cart</h3>

<asp:datalist id="ShoppingCartList" DataKeyField="Name" borderwidth=0


runat="server">

<HeaderTemplate>

<table width="100%">
<tr>
<td width=35>
<b>Qty</b>
</td>
<td width=175>
<b>Product</b>
</td>
<td width=50>
<b>Price</b>
</td>
<td align="right" style="padding-right:10">
<b>Total</b>
</td>
</tr>

</HeaderTemplate>

<ItemTemplate>

<tr>
<td width=35>
<input type=text size=1 id="Qty" runat=server value='<%#
DataBinder.Eval(Container.DataItem, "Quantity") %>'>
</td>
<td width=175>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</td>
<td width=50>
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:C}") %>
</td>
<td align=right style="padding-right:10">
<%# DataBinder.Eval(Container.DataItem, "Total", "{0:C}") %>
</td>
</tr>

</ItemTemplate>

<FooterTemplate>

</table>

</FooterTemplate>
Universal Knowledge Solutions s.a.l 290
</asp:datalist>

<table border=0 width="100%">


<tr>
<td colspan=4><hr></td>
</tr>
<tr>
<td width=52></td>
<td width=225 colspan="2" align="left">
<b>Subtotal</b>
</td>
<td align="right" style="padding-right:10">
<asp:label id="SubTotal" runat=server/>
</td>
</tr>
<tr>
<td width=52></td>
<td width=225 colspan="2" align="left">
<b>Tax</b>
</td>
<td align="right" style="padding-right:10">
<asp:label id="Tax" runat=server/>
</td>
</tr>
<tr>
<td width=52></td>
<td width=225 colspan="2" align="left">
<b>Grand Total</b>
</td>
<td align="right" style="padding-right:10">
<b><asp:label id="Total" runat=server/></b>
</td>
</tr>
</table>

<p>

<div id="CheckoutPanel" runat="server">


<center>
<asp:imagebutton borderwidth=0 OnClick="Recalculate_Click"
ImageUrl='images\recalculate.gif' runat=server/>
<asp:imagebutton borderwidth=0 ImageUrl='images\checkout.gif'
runat=server/>
<asp:imagebutton borderwidth=0 OnClick="ClearCart_Click"
ImageUrl='images\clear_cart.gif' runat=server/>
</center>
</div>

</td>
</tr>
Universal Knowledge Solutions s.a.l 291
</table>
</form>

</body>
</html>

Universal Knowledge Solutions s.a.l 292


Universal Knowledge Solutions s.a.l 293

You might also like