ASP.NET - Basic Controls
ASP.NET - Basic Controls
Button Controls
ASP.NET provides three types of button control:
When a user clicks a button, two events are raised: Click and Command.
Property Description
Text The text displayed on the button. This is for button and link button controls only.
ImageUrl For image button control only. The image to be displayed for the button.
For image button control only. The text to be displayed if the browser cannot display the
AlternateText
image.
Determines whether page validation occurs when a user clicks the button. The default is
CausesValidation
true.
CommandName A string value that is passed to the command event when a user clicks the button.
CommandArgument A string value that is passed to the command event when a user clicks the button.
PostBackUrl The URL of the page that is requested when the user clicks the button.
Label controls provide an easy way to display text which can be changed from one execution of a page to the next. If you want to
display text that does not change, you use the literal text.
Property Description
Specifies the type of text box. SingleLine creates a standard text box, MultiLIne creates a
TextMode text box that accepts more than one line of text and the Password causes the characters
that are entered to be masked. The default is SingleLine.
MaxLength The maximum number of characters that can be entered into the text box.
It determines whether or not text wraps automatically for multi-line text box; default is
Wrap
true.
Determines whether the user can change the text in the box; default is false, i.e., the user
ReadOnly
can not change the text.
The width of the text box in characters. The actual width is determined based on the font
Columns
that is used for the text entry.
The height of a multi-line text box in lines. The default value is 0, means a single line
Rows
text box.
The mostly used attribute for a label control is 'Text', which implies the text displayed on the label.
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.
To create a group of radio buttons, you specify the same name for the GroupName attribute of each radio button in the group. If
more than one group is required in a single form, then specify a different group name for each group.
If you want check box or radio button to be selected when the form is initially displayed, set its Checked attribute to true. If the
Checked attribute is set to true for multiple radio buttons in a group, then only the last one is considered as true.
Property Description
Text The text displayed next to the check box or radio button.
List Controls
ASP.NET provides the following controls
Drop-down list,
List box,
Bulleted list.
These control let a user choose from one or more items from the list. List boxes and drop-down lists contain one or more list items.
These lists can be loaded either by code or by the ListItemCollection editor.
Property Description
The collection of ListItem objects that represents the items in the control. This property
Items
returns an object of type ListItemCollection.
Specifies the number of items displayed in the box. If actual list contains more rows than
Rows
displayed then a scroll bar is added.
The index of the currently selected item. If more than one item is selected, then the index of
SelectedIndex
the first selected item. If no item is selected, the value of this property is -1.
The value of the currently selected item. If more than one item is selected, then the value of
SelectedValue the first selected item. If no item is selected, the value of this property is an empty string
("").
SelectionMode Indicates whether a list box allows single selections or multiple selections.
Property Description
To work with the items in a drop-down list or list box, you use the Items property of the control. This property returns a
ListItemCollection object which contains all the items of the list.
The SelectedIndexChanged event is raised when the user selects a different item from a drop-down list or list box.
The ListItemCollection
The ListItemCollection object is a collection of ListItem objects. Each ListItem object represents one item in the list. Items in a
ListItemCollection are numbered from 0.
When the items into a list box are loaded using strings like: lstcolor.Items.Add("Blue"), then both the Text and Value properties of
the list item are set to the string value you specify. To set it differently you must create a list item object and then add that item to
the collection.
The ListItemCollection Editor is used to add item to a drop-down list or list box. This is used to create a static list of items. To
display the collection editor, select edit item from the smart tag menu, or select the control and then click the ellipsis button from the
Page 5 of 7
Property Description
Item(integer) A ListItem object that represents the item at the specified index.
Methods Description
Adds a new item at the end of the collection and assigns the string parameter to the Text
Add(string)
property of the item.
Inserts an item at the specified index location in the collection, and assigns string
Insert(integer, string)
parameter to the text property of the item.
Insert(integer, ListItem) Inserts the item at the specified index location in the collection.
Remove(string) Removes the item with the text value same as the string.
Property Description
This attribute specifies whether the table tags or the normal html flow to use while
RepeatLayout
formatting the list when it is rendered. The default is Table.
It specifies the direction in which the controls to be repeated. The values available are
RepeatDirection
Horizontal and Vertical. Default is Vertical.
RepeatColumns It specifies the number of columns to use when repeating the controls; default is 0.
Property Description
BulletStyle This property specifies the style and looks of the bullets, or numbers.
It specifies the direction in which the controls to be repeated. The values available are
RepeatDirection
Horizontal and Vertical. Default is Vertical.
RepeatColumns It specifies the number of columns to use when repeating the controls; default is 0.
HyperLink Control
The HyperLink control is like the HTML <a> element.
Property Description
Image Control
The image control is used for displaying images on the web page, or some alternative text, if the image is not available.
Property Description