System.Web.UI.Control WebControl AdRotator BaseDataList DataGrid DataList Button Calendar CheckBox RadioButton HyperLink Image ImageButton Label BaseValidator BaseCompareValidator Custom[r]
Trang 1CH ƯƠ NG III:
HTML SERVERCONTROL VÀ WEB SERVER CONTROL
Lý thuyết 3 tiết
Thực hành 6tiết
Trang 2I HTML Server Control
Các HTML control thông thường nh <h1>, ư
<a>, <input> s không đẽ ược x lý b i server ử ở
mà được g i tr c ti p cho browser đ hi n thử ự ế ể ể ị
Các HTML control có th để ược x lý ngay t i ử ạ
phía server b ng cách chuy n chúng thành ằ ể
các HTML server control.
Trang 3I HTML Server Control
Chuy n m t HTML control thành m t HTML server ể ộ ộ
control b ng cách thêm thu c tính ằ ộ runat=”server”
vào trong các tag HTML
Ví d :ụ
<input type=“text” name=“txtName” runat=“server”/>
<TagName runat=“server”></TagName>
<TagName runat=“server”></TagName>
Trang 4I HTML Server Control
T t c HTML Server Control ph i đấ ả ả ược đ t ặ
trong tag <form> v i thu c tính ớ ộ
runat = “server”
HTML Server Control t n t i bên trong không ồ ạ
gian tên System.Web.UI.HtmlControls
Trang 5H th ng th b c c a HTML Server Controls ệ ố ứ ậ ủ
System.Object System.Web.UI.Control
HtmlControl HtmlImage
HtmlInputControl
HtmlInputFile HtmlInputHidden HtmlInputImage HtmlInputRadioButton
HtmlInputText HtmlInputButton HtmlInputCheckBox
HtmlContainerControl
HtmlForm HtmlGenericControl
HtmlSelect HtmlTable HtmlTableCell HtmlTableRow HtmlTextArea HtmlAnchor HtmlButton
<table>
<form>
<input type=button>
<tr>
<td>,<th>
<input type=text>
<textarea>
<input type=image>
<input type=file>
<input type=hidden>
<input type=radio>
<input type=checkbox>
<select>
<a>
<span>,
<div>,
<button>
<img>
Trang 6I HTML Server Control
onServerClick
onStartSelect,…
Cú pháp:
L u ýư : Function không có tham số.
<tagName event=“Function_Process”></tagName>
<tagName event=“Function_Process”></tagName>
Trang 7I HTML Server Control
Ví d :ụ
<input type=“Submit” value=“Gui” id=“btnSend”
runat=“server”onServerClick=“btnSend_ServerClick”/>
Trang 8I HTML Server Control
Cú pháp:
.innerHTML
controlfield_id.Value
Trang 9I HTML Server Control
Ví d :ụ
<script runat=“server”>
public void btnSend_ServerClick(object
sender,System.EventArgs e)
{
String strName;
strName=txtName.Value;
Response.Write(“Hello :”+strName)
}
</script>
Trang 10<script runat="server">
void Button_ServerClick (object sender, EventArgs e)
{
MySpan InnerHtml = “Chao ban : " + myText.Value +
".";
}
</script></head>
<body>
<form id="myForm" runat="server">
<input type="text" id="myText" runat="server"><br>
<input id="Submit1" type="submit" Value="Click
Here!"
OnServerClick=" Button_ServerClick "
runat="server">
<span id=" MySpan " runat="server"/><b>
</form>
</body>
Trang 11II Web Server Control
ASP.NET. Các control này được x lý trên server ử
và đòi h i ph i có thu c tính ỏ ả ộ runat= “server”
Cú pháp:
<asp:controlname id="some_id" runat="server"/>
Trang 12WebControl AdRotator
BaseDataList
DataGrid
DataList
Button
Calendar
CheckBox
RadioButton
HyperLink
Image ImageButton Label
BaseValidator BaseCompareValidator
CustomValidator RangeValidator
RegularExpressionValidator RequiredFieldValidator
LinkButton ListControl RadioButtonList CheckBoxList DropDownList ListBox Panel Table TableCell TableHeaderCell TableRow
TextBox
ValidationSummary
Repeater
CompareValidator Xml
Trang 13II Web Server Control
Nhóm control c b n ơ ả
Cú pháp chung:
<asp:ControlName runat=“sever” id= ‘ControlID”/>
Trang 14 Label
Textbox
Button
CheckBox and Radio
Image, Hyperlink, Panel
List Controls group
Table
AddRotator
FileUpload
Validation
Trang 15II Web Server Control
Label server control: dùng hi n th văn b n ể ị ả
trên trình duy t.ệ
Thu c tínhộ :
Text: s d ng đ nh n ho c gán textử ụ ể ậ ặ
ví d : ụ
<asp:Label ID=“lblMsg" runat="server">
</asp:Label>
String strName=lblMsg.Text;
Or lblMsg.Text=“Value”;
Trang 16II Web Server Control
TextBox:dùng đ nh p li u t ngể ậ ệ ừ ườ ử ụi s d ng
và hi n th văn b n ch đ c ể ị ả ỉ ọ
Thu c tính : ộ
AutoPostBack: có 2 giá tr True và False khi ị
m t hành đ ng trên trang web b y m t s ộ ộ ẩ ộ ự
ki n.ệ
Ví d : ụ
<asp:TextBox ID=“txtName" runat="server
AutoPostBack=“true”/>
Trang 17II Web Server Control
MultiLine, Password
Ví d :ụ
<asp:TextBox ID=“txtName“ runat="server">
</asp:TextBox>
String strName=txtName.Text;
Ho c txtName.Text=“Value”;ặ
Trang 18II Web Server Control
S ki n: ự ệ
được ch đ nh trên form.ỉ ị
ví d : ụ
txtName.Focus();
Trang 19II Web Server Control
Button : th ng s d ng đ submit formườ ử ụ ể
Phân lo i: ạ
LinkButton
S ki n ự ệ
Onclick()
OnserverClick()
Trang 20II Web Server Control
Các thu c tính: ộ
S ki n: ự ệ