web server controls
TRANSCRIPT
-
8/3/2019 Web Server Controls
1/23
Web Server Controls
Web server controls are special ASP.NET tags understood by the server.
Like HTML server controls, Web server controls are also created on the server and they require
a runat="server" attribute to work. Web server controls do not necessarily map to any existingHTML elements and they may represent more complex elements.
The syntax for creating a Web server control is:
Web Server Control Description
AdRotator Displays a sequence of images
Button Displays a push button
Calendar Displays a calendar
CalendarDay A day in a calendar control
CheckBox Displays a check box
CheckBoxList Creates a multi-selection check box group
DataGrid Displays fields of a data source in a grid
DataList Displays items from a data source by using templates
DropDownList Creates a drop-down list
HyperLink Creates a hyperlink
Image Displays an image
ImageButton Displays a clickable image
Label Displays static content which is programmable (lets you apply content)
LinkButton Creates a hyperlink button
ListBox Creates a single- or multi-selection drop-down list
ListItem Creates an item in a list
Literal Displays static content which is programmable(does not let you
to its content)
Panel Provides a container for other controls
PlaceHolder Reserves space for controls added by code
RadioButton Creates a radio button
RadioButtonList Creates a group of radio buttons
BulletedList Creates a list in bullet format
-
8/3/2019 Web Server Controls
2/23
Repeater Displays a repeated list of items bound to the control
Style Sets the style of controls
Table Creates a table
TableCell Creates a table cell
TableRow Creates a table row
TextBox Creates a text box
Xml Displays an XML file or the results of an XSL transform
common /standard Properties
AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, CssClass, Enabled,
Font, EnableTheming, ForeColor, Height, IsEnabled, SkinID, Style, TabIndex, ToolTip, Width------------------------------------------------------------------------------------------
AdRotator ControlThe AdRotator control is used to display a sequence of ad images.
This control uses an XML file to store the ad information. The XML file must begin and endwith an tag. Inside the tag there may be several tags
which defines each ad.
The predefined elements inside the tag are listed below:
Element Description
Optional. The path to the image file
Optional. The URL to link to if the user clicks the ad
Optional. An alternate text for the image
Optional. A category for the ad
Optional. The display rates in percent of the hits
Properties
Property DescriptionAdvertisementFile The path to the XML file that contains ad information
AlternateTextField A data field to use instead of the Alt text for an advertisement
ImageUrlField A data field to use instead of the ImageURL attribute for an
advertisement
KeywordFilter A filter to limit ads after categories
-
8/3/2019 Web Server Controls
3/23
NavigateUrlField A data field to use instead of the NavigateUrl attribute for anadvertisement
runat Specifies that the control is a server control. Must be set to
"server"
Target Where to open the URL
-------------------------------------------------------------------------------------------------------------
Button Control
The Button control is used to display a push button. it posts the Web page back to the server
when it is clicked.
It may be a submit button (default) or a command button.
By default, this control is a submit button.
A submit button does not have a command name.
A command button allows you to create multiple Button controls on a page.
syntax:
PropertiesProperty Description
CausesValidation Specifies if a page is validated when a Button control is clicked. It has two value
CommandArgument Additional information about the command to perform
CommandName The command associated with the Command event
OnClientClick The name of the function to be called when the button is clicked
PostBackUrl The URL of the page to post to from the current page when the Button control is
Runat Specifies that the control is a server control. Must be set to "server".
Text The text on the button
ValidationGroup The group of controls for which the Button control causes validation when it pos
server
Example
Declare one TextBox control, one Button control, and one Label control in an .aspx file. Whenthe submit button is clicked, the Button1_click subroutine is executed.
-
8/3/2019 Web Server Controls
4/23
default.aspx
-
8/3/2019 Web Server Controls
5/23
Calendar Control
The Calendar control display a calendar in the browser. It displays a one-month calendar from
which user can select dates.
Syntax:
Properties
Property Description
Caption display caption of the calendar
CaptionAlign alignment of the caption text.
Possible values :
y Not sety Topy Bottomy Lefty Right
CellPadding The space (in pixel) between the cell walls and contents.
CellSpacing The space ( in pixels) between cells
DayHeaderStyle The style for displaying the names of the days
DayNameFormat The format for displaying the names of the days possible values are:
y Fully Shorty FirstTwoLettersy Shortest
DayStyle The style for displaying days
FirstDayOfWeek set first day of week
NextMonthText The text displayed for the next month link
NextPrevFormat The format of the next and previous month links
NextPrevStyle The style for displaying next and previous month links
OtherMonthDayStyle The style for displaying days that are not in the current month
PrevMonthText The text displayed for the previous month link
runat Specifies that the control is a server control. Must be set to "server"
SelectedDate store selected date
SelectedDates The selected dates
SelectedDayStyle The style for selected days
SelectionMode How a user is allowed to select dates
-
8/3/2019 Web Server Controls
6/23
SelectMonthText The text displayed for the month selection link
SelectorStyle The style for the month and weeks selection links
SelectWeekText The text displayed for the week selection link
ShowDayHeader A Boolean value that specifies whether the days of the week header shou
ShowGridLines A Boolean value that specifies whether the grid lines between days shoul
ShowNextPrevMonth A Boolean value that specifies whether the next and previous month linkShowTitle A Boolean value that specifies whether the title of the calendar should be
TitleFormat The format for the title of the calendar
TitleStyle The style of the title of the calendar
TodayDayStyle The style for today's date
TodaysDate Today's date
UseAccessibleHeader Specifying whether to use the element for the day headers instead o
VisibleDate The date that specifies the month that is currently visible in the calendar
WeekendDayStyle The style for weekends
OnDayRender The name of the function to be executed when when each day cell is crea
OnSelectionChanged The name of the function to be executed when the user selects a day, weeOnVisibleMonthChanged The name of the function to be executed when the user navigates to a dif
Examples
Declare a Calendar control in an .aspx file. The days are displayed with full names in yellow, theweekends are displayed in green on a yellow background, and the current date is displayed with
a pink background.
-
8/3/2019 Web Server Controls
7/23
H.W.
Display calendar control in various format and display selected date in textbox in variousdate format.
- - - - - -
checkbox control
The CheckBox control is used to display a check box.
Syntax:
Properties
Property Description
AutoPostBack Specifies whether the form should be posted immediately after the Checked not. Default is false
CausesValidation Specifies if a page is validated when a Button control is clicked
Checked Specifies whether the check box is checked or not
InputAttributes Attribute names and values used for the Input element for the CheckBox con
LabelAttributes Attribute names and values used for the Label element for the CheckBox con
runat Specifies that the control is a server control. Must be set to "server"
Text The text next to the check box
TextAlign On which side of the check box the text should appear (right or left)
ValidationGroup Group of controls for which the Checkbox control causes validation when it
OnCheckedChanged The name of the function to be executed when the Checked property has cha
Examples
Declare two TextBox controls and one CheckBox control in an .aspx file. Write an event handler
for the CheckedChanged event to copy the contents of a text box containing the home addressinto a text box that contains the communication address.
-
8/3/2019 Web Server Controls
8/23
Default.aspx:
Permenant address:
Communication address:
defaul.aspx.vb
PartialClass _Default
Inherits System.Web.UI.Page
-
8/3/2019 Web Server Controls
9/23
ProtectedSub Check(ByVal senderAsObject, ByVal e As System.EventArgs) Handles check1.CheckedChanged
Ifcheck1.Checked Then
txtcomm.Text = txthome.Text
Else
txtcomm.Text = ""
EndIf
EndSub
EndClass
-------------------------------------------------------------------------------
The CheckBoxList
The CheckBoxList control is used to create a multi-selection check box group. Each selectableitem in a CheckBoxList control is defined by a ListItem element.
This control supports data binding.
Properties
Property Description
CellPadding The amount of pixels between the border and the contents of the table cell
CellSpacing The amount of pixels between table cells
RepeatColumns The number of columns to use when displaying the check box group
RepeatDirection Specifies whether the check box group should be repeated horizontally or ver
RepeatLayout The layout of the check box group
runat Specifies that the control is a server control. Must be set to "server"
TextAlign On which side of the check box the text should appear
Example
Declare one CheckBoxList control in an .aspx file and write an event handler for the
SelectedIndexChanged event. The selectable list contains five check boxes. When a user checksone of the boxes, the page is immediately posted back to the server, and the Check subroutine is
-
8/3/2019 Web Server Controls
10/23
-
8/3/2019 Web Server Controls
11/23
Default.aspx.vb
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Checkd(ByVal sender As Object, ByVal e As System.EventArgs)
Dim i
label1.Text = "
Selected Hobby :
"Fori = 0 To check1.Items.Count - 1
Ifcheck1.Items(i).Selected Then
label1.Text += check1.Items(i).Text + "
"EndIf
Next
EndSub
---------------------------------------------------------------------------------
DropDownList ControlThe DropDownList control is used to create a drop-down list. Each item in a DropDownListcontrol is defined by a ListItem element.
This control supports data binding.
Properties
Property Description
SelectedIndex It return index of a selected item
OnSelectedIndexChanged name of the function to be executed when the index of the selected item
runat Specifies that the control is a server control. Must be set to "server"
Example:
Default.aspx:
-
8/3/2019 Web Server Controls
12/23
Sub button_click(sender As Object, e As EventArgs)Label1.Text="Your selected Hobby: " & drop1.SelectedItem.Text
End Sub
default.aspx
Cricket
Magic
Origami
Thread art
Chess
-
8/3/2019 Web Server Controls
13/23
------------------------------------------------------------------------------
HyperLink Control
The HyperLink control is used to create a hyperlink.
Properties
Property Description
ImageUrl The URL of the image to display for the link
NavigateUrl The target URL of the link
runat Specifies that the control is a server control. Must be set to "server"
Target The target frame of the URL
Text The text to display for the link
Examples
In this example we declare a HyperLink control in an .aspx file.
-
8/3/2019 Web Server Controls
14/23
DescriptionUrl The location to a detailed description for theimage
GenerateEmptyAlternateText Specifies whether or not the control creates an
empty string as an alternate text
ImageAlign Specifies the alignment of the image in relation toother elements on the web page.
ImageUrl The URL of the image to display for the link
runat Specifies that the control is a server control.Must be set to "server"
Examples
In this example we declare an Image control in an .aspx file.
-
8/3/2019 Web Server Controls
15/23
TagKey
ValidationGroup The group of controls for which the ImageButton control causes valithe server
The properties of the Image control can also be used on the ImageButton control.
When image is clicked, actual location of mouse in image is passed. The position of mouse isrecorded in pixels, and origin (0,0) is upper-left corner of the image.
Example
Declare one ImageButton control and one Label control in an .aspx file. When the user clicks onthe image, the coordinate is executed. It display coordinate.
Default.aspx
Sub Coordinate(sender As Object, e As ImageClickEventArgs)Label1.Text="Coordinates value : " & e.x & ", " & e.y
End Sub
default.aspx.vb
Click on the image:
----------------------------------------------------------------------------------------
Label Control
The Label control is used to display text on a page. The text is programmable. You can apply
styles to its content
-
8/3/2019 Web Server Controls
16/23
Properties
Property Description
runat Specifies that the control is a server control.Must be set to "server"
Text The text to display in the label
Example
Declare one Label control, one TextBox control, and one Button control in an .aspx file. Whenthe user clicks on the button, the button_click is executed. It display content of text box into
label.
Default.aspx.vb
Sub button_click(Sender As Object, e As EventArgs)label1.Text = txt1.Text
End Sub
Default.aspx.vb
Type text in Box:
-----------------------------------------------------------------------------------
-
8/3/2019 Web Server Controls
17/23
ListBox Control
The ListBox control is used to create a single- or multi-selection drop-down list. Each item in a
ListBox control is defined by a ListItem element.
This control supports data binding.
Properties
Property Description
Rows The number of rows displayed in the list
SelectionMode Allows single or multiple selections. Its value is
either single or multiple.
ListControl Standard Properties
AppendDataBoundItems, AutoPostBack, CausesValidation, DataTextField,DataTextFormatString, DataValueField, Items, runat, SelectedIndex, SelectedItem,
SelectedValue, TagKey, Text, ValidationGroup, OnSelectedIndexChanged
The ListControl control covers all the base functions for list controls. Controls that inherits fromthis control include the CheckBoxList, DropDownList, ListBox, and RadioButtonList controls.
Example
Here we declare one ListBox control in an .aspx file. When button is clicked, it display selecteditem, in a Label control.
Default.aspx.vb
Sub Display(Sender As Object,e As EventArgs)Label1.Text="Your hobby is :" & list1.SelectedItem.Text
End Sub
Cricket Magic Origami Thread art
-
8/3/2019 Web Server Controls
18/23
Chess
-----------------------------------------------------------------------------------
ListItem Control
The ListItem control creates an item in a list.
This control is used with the list controls such as , and
Syntax
Properties
Property DescriptionAttributes Optional. A collection of attribute name and value pairs for
the ListItem that are not directly supported by the class
Enabled Optional. Specifies if the item is enabled or disabled
Selected Optional. Specifies whether or not the item is selected
Text Optional. The text displayed in the ListItem
Value Optional. The value of the the ListItem.
It is possible to use the Text or Value properties and the inner HTML text to set the text
displayed for an item in the list.
Text
ListItems with different properties in ListBoxThis example shows a ListBox control with some ListItems in an .aspx file. The items in the list
uses different properties to show the ListItem text.
-
8/3/2019 Web Server Controls
19/23
Text2
ListItem disabled in ListBox
This example shows a ListBox control with one of the ListItems disabled.
ListItem selected in RadioButtonListThis example shows a RadioButtonList control with one of the ListItems selected.
-
8/3/2019 Web Server Controls
20/23
-------------------------------------------------------------------
TextBox Control
The TextBox control is used to create a text box where the user can input text.
Properties
Property Description
AutoCompleteType Specifies the AutoComplete behavior of a TextBox
AutoPostBack specifies whether the control is automatically posted back to the server when thcontents change or not. Default is false
CausesValidation Specifies if a page is validated when a Postback occurs
Columns The width of the textbox
MaxLength The maximum number of characters allowed in the textbox
ReadOnly Specifies whether or not the text in the text box can be changed
Rows The height of the textbox (only used if TextMode="Multiline")
runat Specifies that the control is a server control. Must be set to "server"TagKey
Text The contents of the textbox
TextMode Specifies the behavior mode of a TextBox control (SingleLine, MultiLine or
Password)
ValidationGroup The group of controls that is validated when a Postback occurs
Wrap A Boolean value that indicates whether the contents of the textbox should wrap
or not
OnTextChanged The name of the function to be executed when the text in the textbox has chang
-----------------------------------------------------------------
RadioButton Control
The RadioButton control is used to display a radio button. To create a set of radio buttons using
data binding, use the RadioButtonList control!
-
8/3/2019 Web Server Controls
21/23
Properties
Property Description
AutoPostBack A Boolean value that specifies whether the form should be posted immediahas changed or not. Default is false
Checked A Boolean value that specifies whether the radio button is checked or not
id A unique id for the control
GroupName The name of the group to which this radio button belongs
OnCheckedChanged The name of the function to be executed when the Checked property has ch
runat Specifies that the control is a server control. Must be set to "server"
Text The text next to the radio button
TextAlign On which side of the radio button the text should appear (right or left)
Example
In this example we declare three RadioButton controls, one Button control, and one Label
control in an .aspx file. When the submit button is triggered, the submit subroutine is executed.The submit subroutine may respond in three ways: if the radiobutton with id="red" is selected,
the server sends the message "You selected Red" to the Label control. If the radiobutton withid="green" is selected, the server sends the message "You selected Green" to the Label control. If
the radiobutton with id="green" is selected, the server sends the message "You selected Blue" tothe Label control.
Default.aspx.vb
Sub submit(Sender As Object, e As EventArgs)
ifred.Checked thenLabel1.Text="You selected " & red.Text
elseIf green.Checked thenLabel1.Text="You selected " & green.Text
elseIf blue.Checked thenLabel1.Text="You selected " & blue.Text
end if
End Sub
Default.aspx
-
8/3/2019 Web Server Controls
22/23
Select your favorite color:
--------------------------------------------------------------------
RadioButtonList Control
The RadioButtonList control is used to create a group of radio buttons.
Each selectable item in a RadioButtonList control is defined by a ListItem element!
This control supports data binding
Properties
Property Description
CellPadding The amount of pixels between the border and the contents of the table cell
CellSpacing The amount of pixels between table cells
RepeatColumns The number of columns to use when displaying the radio button group
RepeatDirection Specifies whether the radio button group should be repeated horizontally or vertiRepeatLayout The layout of the radio button group
runat Specifies that the control is a server control. Must be set to "server"
TextAlign On which side of the radio button the text should appear
ListControl Standard Properties
-
8/3/2019 Web Server Controls
23/23
AppendDataBoundItems, AutoPostBack, CausesValidation, DataTextField,DataTextFormatString, DataValueField, Items, runat, SelectedIndex, SelectedItem,
SelectedValue, TagKey, Text, ValidationGroup, OnSelectedIndexChanged
The ListControl control covers all the base functions for list controls. Controls that inherits from
this control include the CheckBoxList, DropDownList, ListBox, and RadioButtonList controls.
Examples
In this example we declare one RadioButtonList control, one Button control, and one Label
control in an .aspx file. Then we create an event handler for the Click event which displays sometext and the selected item, in a Label control.
Sub submit(sender As Object, e As EventArgs)
label1.Text="You selected " & radiolist1.SelectedItem.Text
End Sub
Item 1Item 2Item 3Item 4
-----------------------------------------------------------------------------