bài giảng học phần thiết kế lập trình web chương 4.3 - gv. trần minh hùng

17 366 0
bài giảng học phần thiết kế lập trình web  chương 4.3 - gv. trần minh hùng

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

5/10/2013 I CHƯƠNG IV: HTML SERVERCONTROL VÀ WEB SERVER CONTROL   I   HTML Server Control Chuyển HTML control thành HTML server control cách thêm thuộc tính runat=”server” vào tag HTML Cú pháp: I   HTML Server Control Các HTML control thông thường , , không xử lý server mà gửi trực tiếp cho browser để hiển thị Các HTML control xử lý phía server cách chuyển chúng thành HTML server control HTML Server Control Tất HTML Server Control phải đặt tag với thuộc tính runat = “server” HTML Server Control tồn bên khơng gian tên System.Web.UI.HtmlControls Ví dụ: 5/10/2013  Hệ thống thứ bậc HTML Server Controls I System.Object System.Web.UI.Control HtmlImage HtmlContainerControl HtmlForm HtmlInputControl HtmlInputFile HtmlInputHidden HtmlInputImage HtmlInputButton HtmlInputCheckBox I , HtmlGenericControl , HtmlSelect HtmlTable HtmlInputRadioButton HtmlInputText Các kiện (event) HTML server Control:  onServerClick  onServerChange  onStartSelect,… Cú pháp:  HtmlControl HtmlTableCell , HtmlTableRow HtmlTextArea HTML Server Control HtmlAnchor  Lưu ý: Function khơng có tham số HtmlButton HTML Server Control Ví dụ: I  HTML Server Control Cách lấy liệu từ HTML server Cú pháp: controlfield_id.Value  Đối với tag DIV, SPAN dùng thuộc tính innerHTML 5/10/2013 I HTML Server Control Ví dụ: public void btnSend_ServerClick(object sender,System.EventArgs e) { String strName; strName=txtName.Value; Response.Write(“Hello :”+strName) } II Web Server Control    Web server control tag đặc biệt ASP.NET Các control xử lý server đòi hỏi phải có thuộc tính runat= “server” Web server control tồn bên không gian tên System.Web.UI.WebControls Cú pháp: Ví dụ void Button_ServerClick(object sender, EventArgs e) { MySpan.InnerHtml = “Chao ban : " + myText.Value + "."; } Hệ thống thứ bậc Web Server Control System.Object System.Web.UI.Control Repeater Xml AdRotator LinkButton Image BaseDataList ListControl ImageButton WebControl DataGrid DataList Button Calendar CheckBox RadioButton HyperLink TextBox RadioButtonList CheckBoxList DropDownList ListBox Panel Table TableCell TableHeaderCell TableRow Label BaseValidator BaseCompareValidator CompareValidator RangeValidator CustomValidator RegularExpressionValidator RequiredFieldValidator ValidationSummary 5/10/2013 II Web Server Control Nhóm control  Cú pháp chung: II Web Server Control       Các control gồm:      II Web Server Control  Label server control: dùng hiển thị văn trình duyệt Thuộc tính: Text: sử dụng để nhận gán text ví dụ: V  Validation Server Control Cú pháp: V Validation Server Control  Thuộc tính: ValidationExpression: Khung biểu thức mẫu để so sánh kiểm tra  Cú pháp: * V  Validation Server Control Thuộc tính      ControlToCompare: chứa ID control mà giá trị control ID so sánh với liệu control khác ControlToValidate: chứa ID control mà liệu control so sánh vớI liệu control thuộc tính Operator: Tốn tử so sánh Type : Kiểu liệu để so sánh gồm (String, Integer, Date, Double, Currency) ValueToCompare: chứa giá trị so sánh 14 5/10/2013 V  Các kiện  DataBinding()  Disposed()  Int()  Load(): Lập trình kiện để đặt giá trị ban đầu cho control  PreRender()  Unload() V  Validation Server Control Validation Server Control Thuộc tính   ClientValidationFunction: thuộc tính chứa tên hàm, mà hàm lập trình client (bằng javascript) ControlToValidate: Nhận ID control form để kiểm tra liệu V Validation Server Control CustomValidator Server Control  Kiểm tra tính hợp lệ liệu control theo yêu cầu, ràng buộc đó, hay kiểu liệu người sử dụng định nghĩa trước  CustomValidator Server Control kiểm tra hợp lệ phía client server V  Validation Server Control Các kiện  DataBinding()  Disposed()  Int()  Load(): Lập trình kiện để đặt giá trị ban đầu cho control  PreRender()  ServerValidate(): kiện lập trình server để kiểm tra tính hợp lệ liệu  Unload() 15 5/10/2013 V Validation Server Control Ví dụ: thiết kế form sau, yêu cầu kiểm tra số Pin //Mã giao diện User ID: PIN: Invalid PIN number! //hàm ServerVerify kiểm tra server void ServerVerify(Object Sender, ServerValidateEventArgs Value) { if (txtPIN.Text == "A999") Value.IsValid = true; else Value.IsValid = false; } V Validation Server Control ValidationSummary Server Control: tập hợp thông báo lỗi từ tất điều khiển trang  Cú pháp: 16 5/10/2013 V  Validation Server Control Thuộc tính    DisplayMode: cung cấp định dạng hiển thị Messagebox: List ,BulletList, SingleParagraph HeaderText: Dòng tiêu đề cho thông báo control ShowMessageBox : True thơng báo động, False thơng báo tĩnh ShowSummary: True thị control chạy ứng dụng , False khơng (thường dùng nhất.) V  Validation Server Control Các kiện DataBinding()  Disposed()  Int()  Load(): Lập trình kiện để đặt giá trị ban đầu cho control  PreRender()  Unload()  17 ... DataTable,DataSet,Array,Collection,DataView DataTextField: thiết lập phần tử text từ DataSource DataValueField: thiết lập giá trị phần tử từ DataSource DataBind(): binding data vào ListControl II Web Server Control Các đặc... Items.Clear(): Xoá tất phần tử Items[i].Selected: trả true false True phần tử đựơc chọn Với i=0, n-1 (n=Items.Count) 5/10/2013 II Web Server Control     DataSource: thiết lập giá trị từ DataSource... II Web Server Control    Web server control tag đặc biệt ASP.NET Các control xử lý server địi hỏi phải có thuộc tính runat= “server” Web server control tồn bên khơng gian tên System .Web. UI.WebControls

Ngày đăng: 30/05/2014, 21:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan