在用户控件中自定义属性的方法技巧
有段时间没写什么博客了,一直忙于工作上的事情,白天上班,晚上上课(充电啊+~)
想了想,还是学学微软的很多“讲师”,多写些入门级的技术文章吧,简单易懂,对很多朋友有帮助,看网上有关用户控件的文章比较少,就决定写一篇。
首先,在ASP.NET中,用户控件有几个概念必须弄清楚:
1、它的后缀名为.ASCX
2、它本身不能直接执行
3、它可以由用户自定义它的属性和事件
例如,我们先创建一个用户控件文件,名为 TxtData.ascx ,代码如下:
1
<%@ControlLanguage="C#"AutoEventWireup="true"CodeFile="TxtData.ascx.cs"Inherits="TxtData"%>
2
<linkhref="CSS/CSS.css"rel="stylesheet"type="text/css"/>
3
<styletype="text/css">
4
<!--
5
.STYLE1{
6
font-size:14px;
7
font-weight:bold;
8
}
9
-->
10
</style>
11
<tablewidth="100%"border="0"cellpadding="0"cellspacing="0"class="LeftBorder">
12
<tr>
13
<tdheight="30"bgcolor="#C4DBEE">
14
<spanclass="STYLE1">
15
<asp:LabelID="ClassName"runat="server"Text="Label"></asp:Label>
16
</span>
17
</td>
18
</tr>
19
<tr>
20
<td>
21
<asp:DataListID="DataList1"runat="server"Font-Size="Small"Width="100%">
22
<ItemTemplate>
23
<tablewidth=160border="0">
24
<TRvAlign=top>
25
<TDvAlign=topalign=middleheight=6rowSpan=2>
26
<IMGheight=7src="images/row.gif"width=8>
27
</TD>
28
<TDalign=leftheight=12>
29
<%#GetTxtLink("TxtDataView.aspx?ID="+(int)Eval("ID"),Eval("TxtTitle").ToString(),10)%>
30
31
</TD>
32
</TR>
33
34
</table>
35
</ItemTemplate>
36
37
</asp:DataList>
38
</td>
39
</tr>
40
</table>


2

3


4

5


6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29


30

31

32

33

34

35

36

37

38

39

40

本文地址:http://www.45fan.com/bcdm/67758.html