通过事例学习.net的WebForms技术(一)
/*
豆腐制作,都是精品
http://www.asp888.net 豆腐技术站
如转载 请保留完整版权信息
*/
TextBox:
TextBox 在asp.net中是录入的控件,他有三种形式,分别对应
,
1<input type="password"/>
和
1<textarea>
2这三个HTML标签,在asp.net 中,TextBox的定义格式是
3<asp:textbox ......="" id="text1" runat="server" text="豆腐技术站"></asp:textbox>
4
5代码定义方式
6<script language="C#" runat="server">
7void AddText(){
8TextBox text1=new TextBox();
9text1.Text="豆腐技术站";
10。。。。。。
11}
12</script>
13上面是对TextBox的简单介绍,下面详细来看看TextBox的一些主要的属性和他们的使用方法
14
15AccessKey,可以使该TextBox在页面上通过ALT+[指定键]得到焦点:例如:
16<asp:textbox id="TextBox1" runat="server" text="豆腐制作 http://www.asp888.net"></asp:textbox>
17或者:
18TextBox1.AccessKey="Y";
19
20Attributes, 给TextBox控件的属性赋值,比如:
21TextBox1.Attributes["maxlength"]="20"; 通过Attributes 可以很方便的给TextBox确定一些在HTML
22中很方便的赋值
23
24TextMode 是TextBox 中的一个非常非常重要的一个属性,我们需要利用他来确定我们当前的输入的类型
25他的三种赋值
26TextBox1.TextMode=TextBoxMode.SingleLine; //单行输入框
27TextBox1.TextMode=TextBoxMode.MultiLine; //多行输入框
28TextBox1.TextMode=TextBoxMode.Password; //密码输入框
29
30Text 是我们存取TextBox的输入框中数据的属性,他是可读可写的
31
32此外,还有一些对于TextBox的外观属性的一些控制属性,比如 Font,ToolTip 等等,因为基本上不存在需要在编程
33中控制实现,所以 就 没有在这里详细讲解
34
35Label 是我们在Asp.Net中用来显示输出的控件,对于这个空间我们也是仍然有两种的定义方式
36<asp:label ......="" id="label" runat="server" text="豆腐技术站"></asp:label>
37
38代码定义方式
39<script language="C#" runat="server">
40void AddText(){
41Label label1=new Label();
42label.Text="豆腐技术站";
43。。。。。。
44}
45</script>
46其中,我们最常用的就是Text的属性</textarea>