当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET入门教程:TextBox控件

ASP.NET
Proxy
关于DEV的TreeList控件的使用(1)
用C#给程序加启动画面并只允许一个应用程序实例运行
Vb.net进阶:.NET 中的代码页(CodePage)
XMLHTTP 对象及其方法简介
C#:获得文件版本信息及只读文件的删除
C#:文件的按行读/写及文件目录对话框的使用
What is Mono?
C#:ListBox的2个常用方法Add,Clear与Items的2个属性
使用属性和反射过渡从数据存取层到业务物件1
安装Mono
使用属性和反射过渡从数据存取层到业务物件 - II
Mono介绍(无图片)
[JavaScript]一段把客户端的中文字串转换成UTF-8的代码
Mono 基本概念
Hello Mono
对开发的程序(制作CAB)进行签名,并允许网站中使用
锁住你的EXCEL
DCG升级了!
怎样在C#中调用Delphi6写的DLL

ASP.NET入门教程:TextBox控件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 167 ::
收藏到网摘: n/a

控件用于创建用户可输入文本的文本框。

TextBox 控件

TextBox 控件用于创建用户可输入文本的文本框。

TextBox 控件的属性列在我们的TextBox 控件参考手册中。

属性

属性 描述 .NET
AutoCompleteType 规定 TextBox 控件的 AutoComplete 行为。 2.0
AutoPostBack 布尔值,规定当内容改变时,是否回传到服务器。默认是 false。 1.0
CausesValidation 规定当 Postback 发生时,是否验证页面。 2.0
Columns textbox 的宽度。 1.0
MaxLength 在 textbox 中所允许的最大字符数。 1.0
ReadOnly 规定能否改变文本框中的文本。 1.0
Rows textbox 的高度(仅在 TextMode="Multiline" 时使用)。 1.0
runat 规定该控件是否是服务器控件。必须设置为 "server"。  
TagKey    
Text textbox 的内容。 1.0
TextMode 规定 TextBox 的行为模式(单行、多行或密码)。 1.0
ValidationGroup 当 Postback 发生时,被验证的控件组。  
Wrap 布尔值,指示 textbox 的内容是否换行。 1.0
OnTextChanged 当 textbox 中的文本被更改时,被执行的函数的名称。  

下面的例子演示了您可能在 TextBox 控件中使用到的一些属性:

<html>
<body>
<form runat="server">
A basic TextBox:
<asp:TextBox id="tb1" runat="server" />
<br /><br />
A password TextBox:
<asp:TextBox id="tb2" TextMode="password" runat="server" />
<br /><br />
A TextBox with text:
<asp:TextBox id="tb4" Text="Hello World!" runat="server" />
<br /><br />
A multiline TextBox:
<asp:TextBox id="tb3" TextMode="multiline" runat="server" />
<br /><br />
A TextBox with height:
<asp:TextBox id="tb6" rows="5" TextMode="multiline"
runat="server" />
<br /><br />
A TextBox with width:
<asp:TextBox id="tb5" columns="30" runat="server" />
</form>
</body>
</html>

添加脚本

在下面的例子中,我们在一个 .aspx 文件中声明了一个 TextBox 控件、一个 Button 控件和一个 Label 控件。当提交按钮被触发时,submit 子例程就会被执行。submit 子例程会向 Label 控件写一条文本:

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Your name is " & txt1.Text
End Sub
</script>
<html>
<body>
<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>

在下面的例子中,我们在一个 .aspx 文件中声明了一个 TextBox 控件和一个 Label 控件。当您更改了 TextBox 中的值,并且在 TextBox 外单击时,change 子例程就会被执行。change 子例程会向 Label 控件写一条文本:

<script runat="server">
Sub change(sender As Object, e As EventArgs)
lbl1.Text="You changed text to " & txt1.Text
End Sub
</script>
<html>
<body>
<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server"
text="Hello World!"
ontextchanged="change" autopostback="true"/>
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>