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

ASP.NET
asp.net实现C#代码加亮显示
如何显示在线人数和所在位置
ASP.net生成文字图片
ASP.NET提供文件下载函数
一个简单的ASP.NET Forms 身份认证
在ASP.NET中实现多文件上传
asp.net 2.0中使用sitemapDATAsource做页面导航
通过ASP.net程序创建域帐户故障
为ASP.NET封装的SQL数据库访问类
在ASP.NET中跟踪和恢复大文件下载
SQL存储过程在.NET数据库中的应用
对“学号”、“身份证”的数字分析
把.NET程序部署到没有安装.NET Framwork的机器上
ASP.NET中同时支持简体和繁体中文
几十个ASP.NET性能优化的常用方法
.NET环境下五种邮件发送解决方案
.NET开发中正则表达式中BUG一例
.NET反射、委托技术与设计模式
.net中Windows窗体间的数据交互
ADO.NET访问Oracle 9i存储过程(上)

ASP.NET入门教程:TextBox控件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 59 ::
收藏到网摘: 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>