ASP - e-tahtam.com

34
2008 Pearson Education, Inc. All rights reserved. 1 ASP.NET

Transcript of ASP - e-tahtam.com

Page 1: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

1

ASPNET

2008 Pearson Education Inc All rights reserved

2

Rule One Our client is always right

Rule Two If you think our client is wrong

see Rule One

mdash Anonymous

2008 Pearson Education Inc All rights reserved

3

251 Introduction

ASPNET 20 and Web Forms and Controls

ndash Web application development with Microsoftrsquos ASPNET 20

technology

ndash Web Form files have the filename extension aspx and contain

the Web pagersquos GUI

ndash Every ASPX file created in Visual Studio has a corresponding

class written in a NET language such as Visual Basic C

- Contains event handlers initialization code utility methods and

other supporting code

- Called the code-behind file

- Provides the ASPX filersquos programmatic implementation

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web-

Form Example

Program consists of two related files

ndash ASPX file

ndash C code-behind file

Example

ndash Show the output

ndash Step-by-step process to create the program

ndash Present the code (much of which is generated by Visual

Studio)

4

2008 Pearson Education Inc All rights reserved

WebTimecs

Program Output

5

WebTime ouput

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

6

Adding Web Form for project WebTime (Right click on project in Solution Explorer)

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

7

Click on Add New Item and Add a Web Form for project WebTime

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

8

code-

behind file

ASPX file

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 2: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

2

Rule One Our client is always right

Rule Two If you think our client is wrong

see Rule One

mdash Anonymous

2008 Pearson Education Inc All rights reserved

3

251 Introduction

ASPNET 20 and Web Forms and Controls

ndash Web application development with Microsoftrsquos ASPNET 20

technology

ndash Web Form files have the filename extension aspx and contain

the Web pagersquos GUI

ndash Every ASPX file created in Visual Studio has a corresponding

class written in a NET language such as Visual Basic C

- Contains event handlers initialization code utility methods and

other supporting code

- Called the code-behind file

- Provides the ASPX filersquos programmatic implementation

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web-

Form Example

Program consists of two related files

ndash ASPX file

ndash C code-behind file

Example

ndash Show the output

ndash Step-by-step process to create the program

ndash Present the code (much of which is generated by Visual

Studio)

4

2008 Pearson Education Inc All rights reserved

WebTimecs

Program Output

5

WebTime ouput

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

6

Adding Web Form for project WebTime (Right click on project in Solution Explorer)

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

7

Click on Add New Item and Add a Web Form for project WebTime

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

8

code-

behind file

ASPX file

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 3: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

3

251 Introduction

ASPNET 20 and Web Forms and Controls

ndash Web application development with Microsoftrsquos ASPNET 20

technology

ndash Web Form files have the filename extension aspx and contain

the Web pagersquos GUI

ndash Every ASPX file created in Visual Studio has a corresponding

class written in a NET language such as Visual Basic C

- Contains event handlers initialization code utility methods and

other supporting code

- Called the code-behind file

- Provides the ASPX filersquos programmatic implementation

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web-

Form Example

Program consists of two related files

ndash ASPX file

ndash C code-behind file

Example

ndash Show the output

ndash Step-by-step process to create the program

ndash Present the code (much of which is generated by Visual

Studio)

4

2008 Pearson Education Inc All rights reserved

WebTimecs

Program Output

5

WebTime ouput

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

6

Adding Web Form for project WebTime (Right click on project in Solution Explorer)

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

7

Click on Add New Item and Add a Web Form for project WebTime

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

8

code-

behind file

ASPX file

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 4: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web-

Form Example

Program consists of two related files

ndash ASPX file

ndash C code-behind file

Example

ndash Show the output

ndash Step-by-step process to create the program

ndash Present the code (much of which is generated by Visual

Studio)

4

2008 Pearson Education Inc All rights reserved

WebTimecs

Program Output

5

WebTime ouput

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

6

Adding Web Form for project WebTime (Right click on project in Solution Explorer)

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

7

Click on Add New Item and Add a Web Form for project WebTime

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

8

code-

behind file

ASPX file

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 5: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

WebTimecs

Program Output

5

WebTime ouput

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

6

Adding Web Form for project WebTime (Right click on project in Solution Explorer)

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

7

Click on Add New Item and Add a Web Form for project WebTime

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

8

code-

behind file

ASPX file

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 6: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

6

Adding Web Form for project WebTime (Right click on project in Solution Explorer)

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

7

Click on Add New Item and Add a Web Form for project WebTime

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

8

code-

behind file

ASPX file

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 7: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

7

Click on Add New Item and Add a Web Form for project WebTime

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

8

code-

behind file

ASPX file

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 8: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

8

code-

behind file

ASPX file

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 9: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

9

Solution Explorer window for project WebTime

code-

behind

file ASPX file

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 10: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and

Running a

Simple Web

Form

Example

10

Toolbox in

Visual Web

Developer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 11: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

11

Source mode of Web Forms designer

Design

mode

button

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 12: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple

Web Form Example

12

Split mode of Web Forms designer

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 13: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Creating and Running a Simple Web

Form Example

13

Code-behind file for WebTimeaspxcs generated by Visual Web Developer

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 14: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Designing the Page

bull Designing a Web Form as simple as a Windows Form

bull Use Toolbox to add controls to page in Design

mode

bull Control and other elements are placed

sequentially on a Web Form

bull position is relative to Web Forms upper left corner

bull Alternate type layout (absolute positioning) is

discouraged

14

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 15: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Designing the Page

15

WebFormaspx after adding Label and setting its properties

label

Web Form

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 16: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Adding Page Logic

Open WebTimeaspxcs

Add to Page_Load event handler

display the servers current time in timeLabel

timeLabelText=DateTimeNowToString(hhmmss)

16

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 17: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

Running the Program

Can view the Web Form several ways

ndash Select Debug gt Start Without Debugging

- runs the app by opening it in a browser window

- If created on a local file system URL

httplocalhostPortNumberWebTimeWebTimeaspx

ndash DebuggtStart Debugging

- view web app in a web browser with debugging enabled

- Do you want IDE to modify the webconfig file to enable

debugging Click OK

ndash Finally can open web browser and type the web pagersquos

URL in the Address field

17

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 18: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

WebTimeaspx

lt-- Fig 224 WebTimeaspx --gt

lt-- A page that displays the current time in a Label --gt

lt Page Language=C AutoEventWireup=true CodeFile=WebTimeaspxcs

Inherits=WebTime EnableSessionState=False gt

ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

lthtml xmlns=httpwwww3org1999xhtmlgt

lthead runat=servergt

lttitlegtSimple Web Form Examplelttitlegt

ltstyle type=textcssgt

form1

height 255px

width 655px

style1

font-size large

ltstylegt

ltheadgt

18

This attribute determines how

event handlers are linked to a

controlrsquos events

AutoEventWireUp set to true so

ASPNET treats method of name

Page_eventName as an event handler

for a specified event

Specify class in the code-behind

file from which this ASP NET

document

Document type

declaration specifies

document element

name and URI

Title for web page

Directive to specify

information needed to process file

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 19: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

ltbodygt

ltform id=form1 runat=servergt

ltdivgt

lth2gt

Current time on the Web Serverlth2gt

ltpgt

ampnbspltpgt

ltdivgt

ltaspLabel ID=timeLabel runat=server

BackColor=Black Font-Size=XX-Large

ForeColor=LimegtltaspLabelgt

ltformgt

ltbodygt

lthtmlgt

19 Body tag beginning of Web

pagersquos viewable content

Attribute indicates the

server processes the

form and generates

HTML for client

The aspLabel control maps to

HTML span element ndash markup for

the Label Web control

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 20: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

WebTimeaspxcs The code-behind file for a page that displays the Web servers time using System using SystemConfiguration using SystemData using SystemLinq using SystemWeb using SystemWebSecurity

definitions for graphical controls used in Web Forms using SystemWebUI using SystemWebUIHtmlControls using SystemWebUIWebControls using SystemWebUIWebControlsWebParts public partial class WebTime SystemWebUIPage protected void Page_Load(object sender EventArgs e) display the servers current time in timeLabel timeLabelText = DateTimeNowToString(hhmmss)

20

Contains classes that manage

client requests and server

responses

Contain classes for

creation of Web-based

applications and controls

Set timeLabelrsquos Text

property to Web serverrsquos

time

Event raised when Web page

loads

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 21: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

21

2521 Examining an ASPX File

Examining an ASPX File

ndash ASPNET comments begin with lt-- and terminate with --gt

ndash Page directive

- Specifies the language of the code-behind file

ndash ASPNET markup is not case-sensitive so using a different case

is not problematic

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 22: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

22

2521 Examining an ASPX File

ndash runat attribute

- Indicates that when a client requests this ASPX file

Process the head element and its nested elements on the server

Generate the corresponding XHTML

Sent to the client

ndash asp tag prefix in a control declaration - Indicates that it is an ASPNET Web control

ndash Each Web control maps to a corresponding XHTML element

- When processing a Web control ASPNET generates XHTML markup that will be sent to the client to represent that control in a Web browser

ndash span element

- Contains text that is displayed in a Web page

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 23: ASP - e-tahtam.com

2008 Pearson Education

Inc All rights reserved

23 1 lt-- Fig 251 WebTimeaspx --gt

2 lt-- A page that displays the current time in a Label --gt

3 lt Page Language=VB AutoEventWireup=false CodeFile=WebTimeaspxvb

4 Inherits=WebTime EnableSessionState=False gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtml gt

10 lthead runat=servergt

11 lttitlegtA Simple Web Form Examplelttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth2gt

17 Current time on the Web serverlth2gt

18 ltpgt

19 ltaspLabel ID=timeLabel runat=server BackColor=Black

20 EnableViewState=False Font-Size=XX-Large

21 ForeColor=YellowgtltaspLabelgt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimeaspx

ASPNET comments

Page directive to specify

information needed by

ASPNET to process this file

Document type declaration

Mark up of a label web control

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 24: ASP - e-tahtam.com

2008 Pearson Education

Inc All rights reserved

24 1 Fig 252 WebTimeaspxvb

2 Code-behind file for a page that displays the current time

3 Partial Class WebTime

4 Inherits SystemWebUIPage

5

6 initializes the contents of the page

7 Protected Sub Page_Init(ByVal sender As Object _

8 ByVal e As SystemEventArgs) Handles MeInit

9 display the servers current time in timeLabel

10 timeLabelText = DateTimeNowToString(hhmmss)

11 End Sub Page_Init

12 End Class WebTime

Outline

WebTimeaspxvb

Retrieves the current time and

formats it as hhmmss

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 25: ASP - e-tahtam.com

2007 Pearson Education Inc All rights reserved

25

2525 Examining the XHTML Generated

by an ASPNET Application

bull XHTML Generated by an ASPNET Application

ndash XHTML forms can contain visual and nonvisual components

ndash Attribute method

bull Specifies the method by which the Web browser submits the form to the server

ndash Attribute action

bull Identifies the name and location of the resource that will be requested when this form is submitted

ndash The runat attribute is removed when the form is processed on the server

bull The method and action attributes are added

bull The resulting XHTML form is sent to the client browser

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 26: ASP - e-tahtam.com

2008 Pearson Education

Inc All rights reserved

26 1 lt-- Fig 253 WebTimehtml --gt

2 lt-- The XHTML generated when WebTimeaspx is loaded --gt

3 ltDOCTYPE html PUBLIC -W3CDTD XHTML 11EN

4 httpwwww3orgTRxhtml11DTDxhtml11dtdgt

5

6 lthtml xmlns=httpwwww3org1999xhtml gt

7 ltheadgt

8 lttitlegtA Simple Web Form Examplelttitlegt

9 ltheadgt

10 ltbodygt

11 ltform name=form1 method=post action=WebTimeaspx id=form1gt

12 ltdivgt

13 ltinput type=hidden name=__VIEWSTATE id=__VIEWSTATE value=

14 wEPDwUJODExMDE5NzY5ZGSzVbs789nqEeoNueQCnCJQEUgykw== gt

15 ltdivgt

16

17 ltdivgt

18 lth2gtCurrent time on the Web serverlth2gt

19 ltpgt

20 ltspan id=timeLabel style=colorYellow

21 background-colorBlackfont-sizeXX-Largegt135112ltspangt

22 ltpgt

23 ltdivgt

24 ltformgt

25 ltbodygt

26 lthtmlgt

Outline

WebTimehtml

Declaration for a non-visual

component hidden input

Represents the text in the label

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 27: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

27

Web Controls

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 28: ASP - e-tahtam.com

2007 Pearson Education Inc All rights reserved

28

2531 Text and Graphics Controls

Web control Description

Label Displays text that the user cannot edit

TextBox Gathers user input and displays text

Button Triggers an event when clicked

HyperLink Displays a hyperlink

DropDownList Displays a drop-down list of choices from

which you can select an item

RadioButtonList Groups radio buttons

Image Displays images (eg GIF and JPG)

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 29: ASP - e-tahtam.com

2008 Pearson Education

Inc All rights reserved

29 1 lt-- Fig 2513 WebControlsaspx --gt

2 lt-- Registration form that demonstrates Web controls --gt

3 lt Page Language=VB AutoEventWireup=false

4 CodeFile=WebControlsaspxvb Inherits=WebControls gt

5

6 ltDOCTYPE html PUBLIC -W3CDTD XHTML 10 TransitionalEN

7 httpwwww3orgTRxhtml1DTDxhtml1-transitionaldtdgt

8

9 lthtml xmlns=httpwwww3org1999xhtmlgt

10 lthead runat=servergt

11 lttitlegtWeb Controls Demonstrationlttitlegt

12 ltheadgt

13 ltbodygt

14 ltform id=form1 runat=servergt

15 ltdivgt

16 lth3gtThis is a sample registration formlth3gt

17 ltpgt

18 ltemgtPlease fill in all fields and click Registerltemgtltpgt

19 ltpgt

20 ltaspImage ID=userInformationImage runat=server

21 EnableViewState=False ImageUrl=~Imagesuserpng gt ampnbsp

22 ltspan style=color tealgt

23 Please fill out the fields belowltspangt

24 ltpgt

25 lttable id=TABLE1gt

26 lttrgt

27 lttd style=width 230px height 21px valign=topgt

28 ltaspImage ID=firstNameImage runat=server

Outline

WebControlsaspx

(1 of 5)

Set the color of a specific piece of text

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 30: ASP - e-tahtam.com

2008 Pearson Education

Inc All rights reserved

30 29 EnableViewState=False ImageUrl=~Imagesfnamepng gt

30 ltaspTextBox ID=firstNameTextBox runat=server

31 EnableViewState=FalsegtltaspTextBoxgt

32 lttdgt

33 lttd style=width 231px height 21px valign=topgt

34 ltaspImage ID=lastNameImage runat=server

35 EnableViewState=False ImageUrl=~Imageslnamepng gt

36 ltaspTextBox ID=lastNameTextBox runat=server

37 EnableViewState=FalsegtltaspTextBoxgt

38 lttdgt

39 lttrgt

40 lttrgt

41 lttd style=width 230px valign=topgt

42 ltaspImage ID=emailImage runat=server

43 EnableViewState=False ImageUrl=~Imagesemailpng gt

44 ltaspTextBox ID=emailTextBox runat=server

45 EnableViewState=FalsegtltaspTextBoxgt

46 lttdgt

47 lttd style=width 231px valign=topgt

48 ltaspImage ID=phoneImage runat=server

49 EnableViewState=False ImageUrl=~Imagesphonepng gt

50 ltaspTextBox ID=phoneTextBox runat=server

51 EnableViewState=FalsegtltaspTextBoxgt

52 Must be in the form (555) 555-5555

53 lttdgt

54 lttrgt

55 lttablegt

56 ltpgt

Outline

WebControlsaspx

(2 of 5)

Define a TextBox control used to

collect the userrsquos first name

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 31: ASP - e-tahtam.com

2008 Pearson Education

Inc All rights reserved

31 57 ltaspImage ID=publicationsImage runat=server

58 EnableViewState=False

59 ImageUrl=~Imagespublicationspng gt ampnbsp

60 ltspan style=color tealgt

61 Which book would you like information aboutltspangt

62 ltpgt

63 ltpgt

64 ltaspDropDownList ID=booksDropDownList runat=server

65 EnableViewState=Falsegt

66 ltaspListItemgtVisual Basic 2005 How to Program 3e

67 ltaspListItemgt

68 ltaspListItemgtVisual C 2005 How to Program 2e

69 ltaspListItemgt

70 ltaspListItemgtJava How to Program 6eltaspListItemgt

71 ltaspListItemgtC++ How to Program 5eltaspListItemgt

72 ltaspListItemgtXML How to Program 1eltaspListItemgt

73 ltaspDropDownListgt

74 ltpgt

75 ltpgt

76 ltaspHyperLink ID=booksHyperLink runat=server

77 EnableViewState=False NavigateUrl=httpwwwdeitelcom

78 Target=_blankgt

79 Click here to view more information about our books

80 ltaspHyperLinkgt

81 ltpgt

82 ltpgt

83 ltaspImage ID=osImage runat=server EnableViewState=False

84 ImageUrl=~Imagesospng gt ampnbsp

Outline

WebControlsaspx

(3 of 5)

Defines a

DropDownList

Each item in the drop-

down list is defined by

a ListItem element

Adds a hyperlink

to the web page

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 32: ASP - e-tahtam.com

2008 Pearson Education

Inc All rights reserved

32 85 ltspan style=color tealgt

86 Which operating system are you usingltspangt

87 ltpgt

88 ltpgt

89 ltaspRadioButtonList ID=operatingSystemRadioButtonList

90 runat=server EnableViewState=Falsegt

91 ltaspListItemgtWindows XPltaspListItemgt

92 ltaspListItemgtWindows 2000ltaspListItemgt

93 ltaspListItemgtWindows NTltaspListItemgt

94 ltaspListItemgtLinuxltaspListItemgt

95 ltaspListItemgtOtherltaspListItemgt

96 ltaspRadioButtonListgt

97 ltpgt

98 ltpgt

99 ltaspButton ID=registerButton runat=server

100 EnableViewState=False Text=Register gt

101 ltpgt

102 ltdivgt

103 ltformgt

104 ltbodygt

105 lthtmlgt

Outline

WebControlsaspx

(4 of 5) Defines a

RadioButtonList

control

Each item in the drop-

down list is defined by

a ListItem element

Defines a Button web control

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 33: ASP - e-tahtam.com

2008 Pearson Education

Inc All rights reserved

33

Outline

WebControlsaspx

(5 of 5)

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu

Page 34: ASP - e-tahtam.com

2008 Pearson Education Inc All rights reserved

34

Fig 2514 | DropDownList Tasks smart tag menu