Tải bản đầy đủ (.ppt) (37 trang)

Tài liệu Working with controls ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.03 MB, 37 trang )

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


3
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
4
Server controls vs HTML controls
Feature Server controls HTML controls
Server events
Trigger control-specific events on the
server.

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.


Not all controls require server-side events or state
management.

This is particularly true when doing data binding. Bound items are
usually refreshed from the data source with each request, so it is
more efficient not to maintain state information for bound controls.
 use HTML controls or turn off state management for bound
server controls.

You have complete control over what is rendered with HTML
controls.
Giới thiệu VMWare Workst
ation
6
Difference in HTML tags

Server control:

<asp:controlname id="some_id" runat="server"/>

HTML control:

HTML tags

Examples:

<asp:TextBox id="txtText" runat="server"></asp:TextBox>

<INPUT type="text" id="textfield1">


<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

images
Image, ImageButton Image
Navigation Hyperlink none (use <a> tags in text)
Giới thiệu VMWare Workst
ation
8
Server Controls and HTML Controls
Group controls Panel, Placeholder
Flow Layout,
Grid Layout
Work with dates Calendar none
Display ads AdRotator none
Display horizontal
rules
Literal Horizontal Rule
Get filenames
from client
none File Field
Store data on
page
(provided by state management) Input Hidden
Validate data
RequiredFieldValidator, CompareValidator,
RangeValidator, RegularExpressionValidator,
CustomValidator,ValidationSummary
none (use page-
level)
Giới thiệu VMWare Workst
ation
9

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

text</asp:Label>

Buttons (Button, LinkButton, ImageButton)

<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>

<asp:LinkButton id="LinkButton1"
runat="server">LinkButton</asp:LinkButton>

<asp:ImageButton id="ImageButton1"
runat="server"></asp:ImageButton>

TextBox

<asp:TextBox id="TextBox1"
runat="server"></asp:TextBox>
Giới thiệu VMWare Workst
ation
11
Simple controls
Adjust properties at Design Time
Button
Link Button
Image Button
Giới thiệu VMWare Workst
ation
12
Simple controls
Some common properties

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

14
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

×