范例一:
<html>
<head>
<title>textbox test page</title>
</head>
<body>
<form runat="server">
<table>
<tr>
<td>User Name:</td>
<td><asp:textbox id="name" columns="20" runat="server"/></td>
</tr>
<tr>
<td>Password:</td>
<td><asp:textbox id="password" textmode="password" columns="10" maxlength="10" runat="server"/></td>
</tr>
<tr>
<td>Show Message:</td>
<td><asp:textbox id="show" textmode="multiline" columns="40" rows="10" readonly="true" runat="server"/></td>
</tr>
</table>
</form>
</body>
</html>
范例二:
<script language="c#" runat="server">
public void button_click(Object sender,EventArgs e)
{
show.Text=name.Text;
name.Text="";
}
</script>
<html>
<head>
<title>textbox test page</title>
</head>
<body>
<form runat="server">
<table>
<tr>
<td>User Name:</td>
<td><asp:textbox id="name" columns="20" runat="server"/></td>
</tr>
<tr>
<td>Show Message:</td>
<td><asp:textbox id="show" textmode="multiline" columns="40" rows="10" readonly="true" runat="server"/></td>
</tr>
<tr>
<td colspan="2"><asp:button id="button1" text="Add Text" onclick="button_click" runat="server"/></td>
</tr>
</table>
</form>
</body>
</html>
1:对于textbox控件我们需要注意的是textMode的两个取值类型,一个是multiline另一个就是password.
2:对与textbox另外的属性我们可以通过其他书进行掌握,下面是几个常用的属性
{1}maxlength=num
{2}readonly="true||false"
{3}autopostback="true||false"
{4}TextMode=Multiline||Singleline||Password
{5}Rows
{6}TextChanged事件
当TextBox控件内的文本发生变化的时候,在回发时回触发TextChanged事件,我们可以通过TextBox控件的OnTextChanged为这个事件指定一个处理程序,通常使用此事件时我们需要将textBox控件的autopostback属性设为true(默认是false)。
本文介绍了ASP.NET中的TextBox控件的使用方法,包括两种textMode(multiline和password),并给出了两个实例。第一个例子展示如何创建用户名和密码输入框,以及只读显示区。第二个例子展示了通过Button控件触发事件,更新TextBox的内容。此外,还提到了TextBox的常用属性如maxlength、readonly、autopostback、TextMode等,以及TextChanged事件的使用。
3983

被折叠的 条评论
为什么被折叠?



