1. Trang chủ
  2. » Công Nghệ Thông Tin

Asp.net slide8

22 209 0
Tài liệu đã được kiểm tra trùng lặp

Đ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

Thông tin cơ bản

Định dạng
Số trang 22
Dung lượng 150 KB

Nội dung

Asp.net slide

Session 15Custom Controls in ASP.NET Exploring ASP.NET / Session 15/ 2 of 22ReviewData binding is the process of linking data retrieved from a database to the control, which will display the data. Repeater control is a container control, which can be used to display a list of data. This control has no form of its own.DataList control can be used for displaying data, and it enables to specify the flow of data.Values to be passed to the database for insertion are attached to the command object with the help of the Parameters collection.Assigning the index of the row to be updated to the EditItemIndex property makes that row editable.The System.IO namespace has to be imported to read XML data.XML data can be read only into a DataSet, and not into a DataReader. Exploring ASP.NET / Session 15/ 3 of 22ObjectivesIdentify the need for creating custom controlsCreate simple controls using ASP.NETCreate Composite controls using C#Use events with custom controls Exploring ASP.NET / Session 15/ 4 of 22ControlsJust as classes are built for code re-usability, it also becomes necessary to re-use existing user interface controls Controls help in reusability of visual, as well as functional capabilities Controls also help in packaging these capabilities and redistributing them. ASP.NET controls are mostly used for the web, generating HTML or WML, which is displayed on the client’s browser Exploring ASP.NET / Session 15/ 5 of 22Controls Contd…AssfffghfioiJhjkhjkhjkhjUyuuiyuiyuighghghjgggAssfffghfioiJhjkhjkhjkhjUyuuiyuiyuighghghjgggAssfffghfioiJhjkhjkhjkhjUyuuiyuiyuighghghjgggAssfffghfioiJhjkhjkhjkhjUyuuiyuiyuighghghjgggAssfffghfioiJhjkhjkhjkhjUyuuiyuiyuighghghjgggAssfffghfioiJhjkhjkhjkhjUyuuiyuiyuighghghjgggAssfffghfioiJhjkhjkhjkhjUyuuiyuiyuighghghjgggCode for a dataviewCode for a radiobuttonCode for a checkboxCode for a buttonCode for a datagridCode for a LabelCode for a textbox Exploring ASP.NET / Session 15/ 6 of 22Custom ControlsCreated in two ways ASP.NET like PagePageletsC# Exploring ASP.NET / Session 15/ 7 of 22Custom Control using Label ControlMyLabel.ascx<% @Control Language="C#" Debug="True" %><ASP:Label id="lblOne" runat="server" style="color:Red; font-family: arial; font-size=40pt"></asp:Label><script language="C#" runat="server">public string MyText{ get { // Do Nothingreturn(lblOne.Text); } set { lblOne.Text = value; } Exploring ASP.NET / Session 15/ 8 of 22Custom Control using Label Control}</script>Label.aspx<% @Register Tagprefix="MyFirstControl" TagName="MyLbl" Src="MyLabel.ascx" %><MyFirstControl:MyLbl runat="Server" id ="AllMine" MyText="My first custom control !!!" /> Exploring ASP.NET / Session 15/ 9 of 22Custom Controls Using C#This control is completely programmed using C# and without using any existing controls of ASP.NETRepeater.csusing System;using System.Web;using System.Web.UI;namespace MyOwnControls{ public class TextRepeater : Control { protected override void Render(HtmlTextWriter writer) { int intCount; Exploring ASP.NET / Session 15/ 10 of 22Custom Controls Using C# for (intCount=1; intCount<=3; intCount++) { writer.Write ("<h1>This is a custom control</h1><br>"); } } }}The code is saved with a .cs extension since it is a C# file, which will be compiled into an assembly. This is done by typing the following command at the DOS prompt.csc /t:library /r:System.dll,System.Web.Dll Repeater.csThe command creates Repeater.dll, which is placed in the bin directory of the application. [...]... more simple controls, are known as Composite controls Composite controls can comprise custom controls, as well as windows controls Every ASP.NET page which includes at least one control, can be referred (the ASP.NET page itself) to as a composite control Exploring ASP.NET / Session 15/ 16 of 22 Composite Controls - Example Composite.cs using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;... ArgumentException("The text should not be more than 25 characters"); else myText = value; } } Exploring ASP.NET / Session 15/ 14 of 22 Properties of Custom Controls protected override void Render(HtmlTextWriter writer) { for (int Count = 1; Count 10) throw new ArgumentException ("The text should not be repeated more than 10 times"); else timesToRepeat = value; } } Exploring ASP.NET / Session 15/ 13 of 22 Properties of Custom Controls... Exploring ASP.NET / Session 15/ 17 of 22 Composite Controls - Example set { this.EnsureChildControls(); ((TextBox)Controls[1]).Text = value.ToString(); } } protected override void CreateChildControls() { this.Controls.Add(new LiteralControl("Value: ")); TextBox box = new TextBox(); box.Text = "0"; this.Controls.Add(box); this.Controls.Add(new LiteralControl("")); } } } Exploring ASP.NET /... OnClick="AddBtn_Click" runat="server" ID="btnAdd" /> Exploring ASP.NET / Session 15/ 20 of 22 Composite Controls - Output Exploring ASP.NET / Session 15/ 21 of 22 Summary       Controls help in reusability of visual, as well as functional capabilities Custom web controls can be created in two... HTML automatically Custom Controls, which compose of other controls as well, are known as composite controls The System.Web.UI.INamingContainer interface has no methods; it is used by ASP.NET to create unique IDs Exploring ASP.NET / Session 15/ 22 of 22 ... follows: Custom control using C# Exploring ASP.NET / Session 15/ 11 of 22 Properties of Custom Controls    In order to enable a better reuse of the control it is possible to create properties for the control These properties can be modified... language="C#" runat="server"> private void AddBtn_Click(Object sender, EventArgs e) { MyComposition1.Val = MyComposition1.Val + 1; } private void SubtractBtn_Click(Object sender, EventArgs e) Exploring ASP.NET / Session 15/ 19 of 22 Composite Controls - Example { MyComposition1.Val = MyComposition1.Val - 1; } . a textbox Exploring ASP. NET / Session 15/ 6 of 22Custom ControlsCreated in two ways ASP. NET like PagePageletsC# Exploring ASP. NET / Session 15/ . controls Every ASP. NET page which includes at least one control, can be referred (the ASP. NET page itself) to as a composite control Exploring ASP. NET / Session

Ngày đăng: 15/11/2012, 14:44

Xem thêm

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN