0% found this document useful (0 votes)
6 views25 pages

Module1 Part2

This document introduces server controls in ASP.NET, which are essential components for creating user interfaces, including various types such as standard, data, validation, navigation, login, and AJAX extensions. It explains how to handle control events, set focus, and utilize access keys, along with detailed descriptions of specific controls like buttons, text boxes, check boxes, and more. Additionally, it covers attributes and properties associated with these controls to enhance user interaction and data handling.

Uploaded by

Midhun Manoj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views25 pages

Module1 Part2

This document introduces server controls in ASP.NET, which are essential components for creating user interfaces, including various types such as standard, data, validation, navigation, login, and AJAX extensions. It explains how to handle control events, set focus, and utilize access keys, along with detailed descriptions of specific controls like buttons, text boxes, check boxes, and more. Additionally, it covers attributes and properties associated with these controls to enhance user interaction and data handling.

Uploaded by

Midhun Manoj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

MODULE 1 -Part 2

INTRODUCTION TO SERVER CONTROLS


 Server controls are small building blocks of the graphical user interface,
which include text boxes, buttons, check boxes, list boxes, labels, and
numerous other tools. Using these tools, the users can enter data, make
selections and indicate their preferences.

 Server controls are also used for structural jobs, like validation, data
access, security, creating master pages, and data manipulation.

 Six different types of server controls in ASP.NET

TYPES OF SERVER CONTROLS

• Standard

• Data

• Validation

• Navigation

• Login

• AJAX Extensions

Standard

• Commonly used user input controls such as labels, text boxes, and drop-
down lists

• Many can be bound to a data source


Data

 Databound user-interface controls that display data via a data source


control

 Data source controls that access data from a variety of databases,


XML data sources, and business objects

Validation

 Used to validate user input


 Work by running client-side scripts
 Can handle most validation requirements

Navigation

• Controls that provide menus and path maps for navigating a web site

Login

 . Controls that provide user authentication

AJAX Extensions

• Controls that provide for updating selected parts of a page during a


postback
DESCRIPTION

o The button, image button and link button controls all provide the
same functionality. They differ only in how they appear on the form

o The check box list and radio button list controls serve as containers
for a collection of checkbox or radio button items. They are typically
used to create a list of check boxes or radio buttons that are bound to
a data source
TWO WAYS TO HANDLE CONTROL EVENTS

 An event handler is a Sub procedure that's called when a specified event


occurs.

 By default, Visual Studio creates an event handler by including a Handles


clause on the Sub procedure. The Handles clause names the control and
event that the procedure handles. When you use this technique, you can
give the procedure any name you want.

 You can also code an event handler without a Handles clause. Then, you
have to name the handler in the appropriate event attribute of the control.
For example, you can use the OnClick attribute to name the procedure
that's executed when the user clicks a control.

COMMON CONTROL EVENTS


ACCESS KEYS WITH WEB SERVER CONTROLS

o You can use the AccessKey attribute on a web server control to specify a
keyboard shortcut for the control. To use the keyboard shortcut, the user
holds down the Alt key and presses the access key to move the focus to the
control.

o If you use a label to identify another control, you can set the AccessKey
attribute for the label and then set the AssociatedControlID attribute to the
other control. When the user presses the access key for the label, the focus
will be moved to the associated control.

HOW TO SET FOCUS ON A WEB SERVER CONTROL

• You can set the control that receives the focus when a form is first
displayed using the DefaultFocus attribute of the form. To move the focus
to a control at runtime, use the Focus method of the control.

• You can set the button that causes a form to be posted back when you
press the Enter key using the DefaultButton attribute of the form.

FORM THAT USES ACCESS KEYS AND DEFAULT FOCUS AND BUTTONATTRIBUTES
I) HOW TO WORK WITH BUTTONS, LINK BUTTONS,
IMAGE BUTTONS

 When a user clicks a button, link button, or image button, the page
specified in the PostBackUrl attribute is loaded and executed. If this
attribute isn't included, the page is posted back to the server and the
Click and Command events are raised. You can code event handlers
for either or both of these events.
COMMON BUTTON ATTRIBUTES
Properties of the CommandEventArgs class
I) TEXT BOX AND LABELS

• Text box controls are typically used to accept input from the user. A text
box can accept one or more lines of text depending on the setting of the
TextMode attribute.

• Label controls provide an easy way to display text that can change from
one execution of an ASP.NET page to the next. To display text that doesn't
change, you typically use literal text.
COMMON TEXT BOX ATTRIBUTES
II) CHECK BOX AND RADIO BUTTON
• A check box displays a single option that the user can either check or uncheck.
Radio buttons present a group of options from which the user can select just one
option. All of the radio buttons in a group should have the same group name.

• If you want a check box or radio button to be selected when it's initially
displayed, set its Checked attribute to True. If you set the Checked attribute of
more than one radio button in the same group to True, only the last one will be
selected.
III) RADIO BUTTON LIST AND CHECK BOX LIST

 A radio button list presents a list of mutually exclusive options. A check box
list presents a list of independent options. These controls contain a
collection of ListItem objects that you refer to through the Items property
of the control.

 These controls also have SelectedItem, SelectedIndex, and SelectedValue


properties. These properties work just like they do for drop-down list and
list box controls.
IV) BULLETED LIST AND NUMBERED LIST
 The bulleted list control creates bulleted lists or numbered lists. This
control contains a collection of ListItem objects that you refer to
through the Items property of the control.

 If you set the DisplayMode attribute to Hyperlink, you can set the Value
attribute of each ListItem object to the URL of the page you want to
display when the link is clicked.

 If you set the DisplayMode attribute to LinkButton, you can use the
Click event of the bulleted list to respond to the user clicking one of the
links.

 Unlike the other list controls, the bulleted list control doesn't have
SelectedItem, SelectedIndex, and SelectedValue properties.
V) IMAGE CONTROL

• An image control displays a graphic image, typically in GIF (Graphic


Interchange Format), JPEG (Joint Photographic Experts Group), or PNG
(Portable Network Graph- ics) format.

• If you don't specify the Height or Width attributes of an image


control, the image will be displayed at full size unless the size is
specified by CSS.

VI) HYPERLINK CONTROL

 A hyperlink control navigates to another web page when the user


clicks the control. You can display either text or an image for the
control.
VII) FILE UPLOAD CONTROL

• The file upload control displays a text box and a button that lets the user
browse the client computer's file system to locate a file to be uploaded.

• Because the file upload control doesn't provide a button to upload the file,
you must provide a button or other control to post the page. Then, in the
button's Click event procedure, you must call the SaveAs method of the file
upload control to save the file on the server.

• To use the SaveAs method, the user must have write access to the specified
directory.
VIII) IMAGE MAP CONTROL

 The image map control lets you display an image map with one or more
hot spots. The page either posts back or links to another page when the
user clicks a hot spot.

 To post the page back when the user clicks a hot spot, set the
HotSpotMode attribute to PostBack, and set the PostBack Value
attribute of the hot spot to the value you want passed to the Click event
procedure.

 To link to another page when the user clicks a hot spot, set the
HotSpotMode attribute to Navigate and specify the URL of the page in
the NavigateUrl attribute of the hot spot.
IX) CALENDAR CONTROL

• The calendar control is typically used to provide users with an easy way of
selecting a date. Entire weeks and months can also be selected.

• When the user makes a selection from a calendar control, the SelectionChanged
event is raised and the page is posted to the server.

You might also like