当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > ASP.NET - TextBox(文本框)控件

ASP.NET
ASP.NET 2.0 - Navigation 导航
C#中new和override区别
ASP.NET中 Bin,App_Browser,App_code,App_Data,App_Theme 等文件

ASP.NET - TextBox(文本框)控件


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

The TextBox control is used to create a text box where the user can input text.
文本框控件可用来创建用户输入文字用的文本框。


The TextBox Control
文本框控件

The TextBox control's attributes and properties are listed in our web controls reference page.
在我们的WEB控件参考页中罗列了文本框控件的所有属性。

The example below demonstrates some of the attributes you may use with the TextBox control:
下面所要演示的是你在使用文本框控件时可能会用到的一些属性:

Example(举例)

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

 


Add a Script
添加脚本

The contents and settings of a TextBox control may be changed by server scripts when a form is submitted. A form can be submitted by clicking on a button or when a user changes the value in the TextBox control.
当表单被提交时可通过服务来调整文本框的内容和设定。一张表单可通过点击按钮或是当用户改变文本框的内容时进行提交。

In the following example we declare one TextBox control, one Button control, and one Label control in an .aspx file. When the submit button is triggered, the submit subroutine is executed. The submit subroutine writes a text to the Label control:
在下面的举例中我们在一个.aspx文件中声明了一个文本框控件,含有一个按钮控件,一个标签控件。当触发了提交按钮,提交的子程序给予执行。提交的子程序会在标签控件里写上一些文字:

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

Example(举例)

In the following example we declare one TextBox control and one Label control in an .aspx file. When you change the value in the TextBox and either click outside the TextBox or press the Tab key, the change subroutine is executed. The submit change subroutine writes a text to the Label control:
在下面的举例中我们将在一个.aspx文件中声明一个文本框控件以及一个标签控件。当你改变了文本框的内容并将焦点移离文本框(鼠标点文本框的外面或是按了Tab键),change 子程序将给予执行。change子程序会在标签控件上写上一些文字:

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

Example(举例)

评论 (1) 1 All

登陆 | 还没注册?