首页


ASP .NET教程

  • ASP .NET简介
  • ASP与ASP .NET
  • 安装ASP .NET
  • ASP .NET网页
  • ASP .NET控件
  • ASP .NET事件
  • ASP .NET表单

  • ASP .NET Form
  • ASP .NET ViewState
  • asp:TextBox
  • asp:Button
  • ASP.NET绑定

  • 数据绑定
  • ArrayList
  • Hashtable
  • SortedList
  • XML文件
  • asp:Repeater
  • asp:DataList
  • ASP.NET数据库

  • 数据库连接
  • 手册

  • HTML控件
  • Web控件
  • 验证控件
  • 示例

  • ASP .NET示例

  • ASP .NET - TextBox控件

    [前一节] [后一节]

    TextBox控件用来创建一个可供用户输入文本的文本框。


    TextBox控件

    TextBox控件用来创建一个可供用户输入文本的文本框。

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

    下面的例子演示了你可能会用到的TextBox控件的一些属性:

    <html>
    <body>
    
    <form runat="server">
    
    基本的TextBox:
    <asp:TextBox id="tb1" runat="server" />
    <br /><br />
    
    用于输入密码的TextBox:
    <asp:TextBox id="tb2" TextMode="password" runat="server" />
    <br /><br />
    
    带有文本的TextBox:
    <asp:TextBox id="tb4" Text="Hello World!" runat="server" />
    <br /><br />
    
    多行的TextBox:
    <asp:TextBox id="tb3" TextMode="multiline" runat="server" />
    <br /><br />
    
    具有高度的TextBox:
    <asp:TextBox id="tb6" rows="5" TextMode="multiline"
    runat="server" />
    <br /><br />
    
    具有宽度的TextBox:
    <asp:TextBox id="tb5" columns="30" runat="server" />
    
    </form>
    
    </body>
    </html>


    添加脚本

    TextBox控件的内容和设置可在提交表单时被服务器脚本修改。通过点击按钮或是用户改变TextBox控件的值时表单都可以被提交。

    在下面的示例中我们在一个.aspx文件中定义一个TextBox控件、一个Button控件和一个Label控件。当提交按钮被触发,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以外的区域还是按Tab键,change子程序都会被运行。submit子程序向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>

    [前一节] [后一节]


    本站教程均为老猫根据外文资料翻译整理,将逐步刊出。此版本内容保证国内绝无仅有,由于时间、水平有限,有不妥之处欢迎指正。

    如果能对您有所帮助,敬请赞助,老猫不胜感激!

    1. 网上乞讨:
    在您任何方便的时候,向以下帐号存入10元人民币(当然越多越好)。
    交通银行太平洋卡
    601428 7091 5592604

    2. 广告投放:
    在任何指定页面投放各种形式广告,价格优惠。

    3. 代为宣传:
    以任何形式向您的亲朋好友推荐。

    Copyright © Tom.s Online 2003-2004