Module1 Part2
Module1 Part2
Server controls are also used for structural jobs, like validation, data
access, security, creating master pages, and data manipulation.
• Standard
• Data
• Validation
• Navigation
• Login
• AJAX Extensions
Standard
• Commonly used user input controls such as labels, text boxes, and drop-
down lists
Validation
Navigation
• Controls that provide menus and path maps for navigating a web site
Login
AJAX Extensions
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
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.
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.
• 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.
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
• 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.