Unit - 2 ASP.NET Controls
Unit - 2 ASP.NET Controls
NET CONTROLS
1
ASP.NET CONTROLS
events on them
2
SERVER CONTROLS
Four types of server controls:
HTML server controls: server-based equivalent for
standard HTML elements
Web controls: more object properties and events + new
types of controls not in HTML
Validation controls: check user inputs
User controls: developer designed controls
3
HTML SERVER CONTROLS
An object interface for standard HTML elements
Generate equivalent interface
Retain their state
Fire events
Add the attribute “runat=serevr” and an id to the
HTML element start tag
4
HTML SERVER CONTROLS
Traditional HTML form
<html> <body>
<form method="post">
Enter Number of hours: <input type=text >
<input type=submit value="convert to seconds">
</form></body></html>
6
HTML Server Control Description
HtmlAnchor Controls an <a> HTML element
8
WEB CONTROLS
Provide rich user interface (mapped to more than
one HTML element)
Provide more properties, events and methods than
HTML tags
Detect browser type and adjust output automatically
them.
Object properties are mapped to attributes
11
WEB CONTROLS
All web controls have:
BackColor, BorderColor and ForeColor
BorderWidth, BorderStyle
Font
Height, Width
TabIndex, AccessKey
Enabled, visible, EnableViewState
TextBox control properties:
TextMode: SingleeLine, MultipleLine, Password
MaxLength: maximum number of characters accepted
Columns: width of the control
Rows: display height of the control
12
WEB CONTROLS
Button / label:
text
CheckBox / RadioButton :
BackImageUrl
13
WEB CONTROLS
Table:
Properties: BackImageUrl, CellPadding,Cellspacing,
GridLines
Rows a collection of TableRow objects
TableRow
ColumnSpan/RowSpan
HorizontalAlign / VerticalAlign
text
14
LIST CONTROLS
ListBox, DropDownList, CheckBoxList, RadioButtonList
Items: Collection of “ListItem” objects, which has:
16
PAGE LIFECYCLE
When the user changes a control that has auto postback
set to true:
1. Java script is invoked and the page is resubmitted
2. ASP.NET recreates page object from .aspx file
3. ASP.NET retrieves state information from hidden
fields and updates controls
4. Execute Page_load event handler
5. Execute appropriate event handlers
6. Execute page_unload event handler and render
page
17
7. Send page to client
PAGE PROCESSING STEPS
Web page request ASP.NET creates page objects
from aspx code
19
VALIDATION CONTROLS
HTML does not facilitate validation of user input
ASP.NET provide validation controls that checks the
20
VALIDATION CONTROLS
RequiredFieldValidator
RangeValidator
CompareValidator
RegularExpressionvalidator
CustomValidator
ValidationSummary
21
VALIDATION CONTROLS
To activate the validation controls before the form is
submitted, set button property “Causes Validation” to
true
Each validation control is bound to one input control.
controls
22
VALIDATION CONTROLS
Common properties
ControlToValidate
ErrorMessage: text to display if validation fails
ForeColor
Display: add message dynamic or static
IsValid: true or false depending on the validation result
Enabled
EnableClientSideScript
23
VALIDATION CONTROLS
RequiredFieldValidator
initialValue
RangeValidator
MaximumValue, MinimumValue, Type
CompareValidator
ControlToCompare, Operator,Type, ValueToCompare
RegularExpressionvalidator
ValidationExpression
24
REGULAR EXPRESSION
CHARACTERS
* 0 or more occurrence of previous character or expression
25
VALIDATION SUMMARY
Displays all the errors that happened in the page in
one area
Message in the errorMessage properties will be
Other properties
HeaderText
ShowMessageBox / ShowSummary
26
27