ASP-textbox控件用法

本文介绍了ASP.NET中的TextBox控件的使用方法,包括两种textMode(multiline和password),并给出了两个实例。第一个例子展示如何创建用户名和密码输入框,以及只读显示区。第二个例子展示了通过Button控件触发事件,更新TextBox的内容。此外,还提到了TextBox的常用属性如maxlength、readonly、autopostback、TextMode等,以及TextChanged事件的使用。

范例一:

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值