aspnet
aspnet
Working with controls
Working with controls
Hà Đồng Hưng
Giới thiệu VMWare Workst
ation
2
Objectives
•
Server controls vs HTML controls
•
Simple controls
–
Label, Buttons (Button, LinkButton, ImageButton),
TextBox
–
List Controls (ListBox, DropDownList, Table,DataGrid,
DataList, Repeater )
•
Data Binding with controls
–
Simple Data Binding
–
Data Binding with Database
•
Validation controls
•
Other controls
Giới thiệu VMWare Workst
ation
Can trigger only page-level
events on server (post-back)
State
Management
Data entered in a control is maintained
across requests.
Data is not maintained; must be
saved and restored using page-
level scripts
Adaptation
Automatically detect browser and adapt
display as appropriate.
No automatic adaptation; must
detect browser in code or write
for least common denominator
Properties
The .NET Framework provides a set of
properties for each control. Properties
allow you to change the control' s
appearance and behavior within server-
side code.
HTML attributes only
Giới thiệu VMWare Workst
ation
5
Using HTML controls ???
Use HTML controls for the following reasons:
•
Migration from earlier versions of ASP.
•
<asp:Button id="btnShow" runat="server"
Text="Show"></asp:Button>
–
<INPUT type="button" value="Show">
Giới thiệu VMWare Workst
ation
7
Server Controls and HTML Controls
Server controls HTML controls
Display text Label, TextBox, Literal
Label, Text Field, Text Area,
Password Field
Display
tables
Table, DataGrid Table
Select from
list
DropDownList, ListBox, DataList,
Repeater
List Box, Dropdown
Perform
commands
Button, LinkButton, ImageButton
Button, Reset Button, Submit
Button
Set values
CheckBox, CheckBoxList, RadioButton,
RadioButtonList
Checkbox, Radio Button
Display
Objectives
•
Server controls vs HTML controls
•
Simple controls
–
Label, Buttons (Button, LinkButton, ImageButton),
TextBox
–
List Controls (ListBox, DropDownList, Table,DataGrid,
DataList, Repeater )
•
Data Binding with controls
–
Simple Data Binding
–
Data Binding with Database
•
Validation controls
•
Other controls
Giới thiệu VMWare Workst
ation
10
Simple controls
Label, Buttons, TextBox - HTML tags
•
Label
–
<asp:Label id="Label1" runat="server">Please input
Property Use to
Text Get or set the data in the TextBox.
TextMode
Display SingleLine, MultiLine (scrollable),
or Password text.
Enabled Enable/Disable the TextBox
Visible Show/Hide the TextBox
ReadOnly Prevent the user from changing the text.
AutoPostBack
When set to True, causes the TextBox to fire a TextChanged post-
back event when the user leaves the TextBox after changing the
contents.
• Label, Buttons
–
Text property
• TextBox
Giới thiệu VMWare Workst
ation
13
Recheck TextBox properties
If txtUser.Text = "Guest" And txtPassWord.Text = "Moon" Then
Response.Redirect("Webform2.aspx")
Else
txtUser.ReadOnly = True
txtPassword.ReadOnly = True
End If
Write code to do
these:
Giới thiệu VMWare Workst
ation