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

Asp.net slide8

22 210 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

Tiêu đề Custom Controls in Asp.net
Trường học Standard University
Chuyên ngành Computer Science
Thể loại Bài tập
Năm xuất bản 2023
Thành phố Hanoi
Định dạng
Số trang 22
Dung lượng 150 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Asp.net slide

Trang 1

Session 15

Custom Controls in

ASP.NET

Trang 2

 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

Trang 3

controls

Trang 4

 Just as classes are built for code re-usability, it

also becomes necessary to re-use existing user

 ASP.NET controls are mostly used for the web,

generating HTML or WML, which is displayed on the client’s browser

Trang 5

Controls Contd…

Assfffghfioi Jhjkhjkhjkhj Uyuuiyuiyui ghghghjggg

Assfffghfioi Jhjkhjkhjkhj Uyuuiyuiyui ghghghjggg

Assfffghfioi Jhjkhjkhjkhj Uyuuiyuiyui ghghghjggg

Code for a dataview

Code for a radiobutton

Code for a checkbox

Code for a button

Code for a datagrid

Code for a Label

Code for a textbox

Trang 6

Custom Controls

Created in two ways

ASP.NET like Page

Pagelets

C#

Trang 7

Custom Control using Label

Control

MyLabel.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

Trang 8

Custom Control using Label Control

<MyFirstControl:MyLbl runat="Server" id ="AllMine"

MyText="My first custom control !!!" />

Trang 9

Custom Controls Using C#

This control is completely programmed using C# and without using any existing

Trang 10

Custom Controls Using C#

for (intCount=1; intCount<=3; intCount++)

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.cs

The command creates Repeater.dll, which is placed in the bin directory of the

application

Trang 11

Custom Controls Using C#

The custom control created using C# can be used in an aspx page as follows:

<% @Register TagPrefix="Mine" Namespace="MyOwnControls"

Trang 12

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 dynamically, thus allowing the

user to use the control in most flexible manner

 The code Repeater.cs in the previous example can be modified to

specify the text to be printed and the number of times it should be

Trang 13

Properties of Custom Controls

public string myText;

public int TimesToRepeat

else timesToRepeat = value;

}

}

Trang 14

Properties of Custom Controls

public string MyText

else myText = value;

}

}

Trang 15

Properties of Custom Controls

protected override void Render(HtmlTextWriter writer)

Trang 16

Composite Controls

 Simple controls can be clubbed together to form more complex controls

 Complex controls, which comprise one or 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

Trang 17

Composite Controls - Example

this.EnsureChildControls();

return Int32.Parse (((TextBox) Controls[1]) Text); }

Trang 18

Composite Controls - Example

set { this.EnsureChildControls();

((TextBox)Controls[1]).Text = value.ToString();

} }

protected override void CreateChildControls()

{

this.Controls.Add(new LiteralControl("<h3>Value: "));TextBox box = new TextBox();

Trang 19

Composite Controls - Example

This composite control created can be used within a aspx page, just like any

other custom control that has been created

<script language="C#" runat="server">

private void AddBtn_Click(Object sender, EventArgs e)

Trang 20

Composite Controls - Example

<asp:button text="Subtract" OnClick="SubtractBtn_

Click" runat="server" ID="btnSubtract" />

</form>

</body>

</HTML>

Trang 21

Composite Controls - Output

Trang 22

 Web Controls using C#

 Pagelets are custom controls that look like an asp page, and have the extension ascx

 Web Controls render 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

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