asp.net学习之textbox控件使用的小例子
2014-11-25 22:10
429 查看
.apsx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sample 3-03.aspx.cs" Inherits="Sample_3_1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> <title></title> </head> <body> <form id="form1" runat="server"> <div> <h3>输入正确的姓名和密码(123456),解锁控件</h3> <div class="d1"> 姓名:<asp:TextBox ID="txt_name" runat="server"></asp:TextBox> <br /> 密码:<asp:TextBox ID="txt_pwd" runat="server" ontextchanged="txt_pwd_TextChanged" AutoPostBack="true" TextMode="Password" ></asp:TextBox> </div> <br /> <br /> <br /> <asp:Panel runat="server" ID="pnl_result" Enabled="false" > <h3>拆分单行文本框的字符串,在多行文本框中显示</h3> <asp:TextBox ID="txt_org" runat="server" Height="26px" Width="210px"></asp:TextBox> <asp:Button ID="btn_split" runat="server" Text="拆分字符串" onclick="btn_split_Click" /> <br /> <asp:TextBox ID="txt_result" runat="server" TextMode="MultiLine" rows="10" Width="210px" ></asp:TextBox> </asp:Panel> </div> </form> </body> </html>
.apsx.cs代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Sample_3_1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void txt_pwd_TextChanged(object sender, EventArgs e) { //如果有输入姓名,且密码框内容为“123456”,则解锁PANEL,否则锁定 if (txt_name.Text != "" && txt_pwd.Text == "123456") { //逐个控件解锁 /* txt_org.Enabled = true; txt_result.Enabled = true; btn_split.Enabled = true;*/ //通过解锁PANEL,一次性解锁控件 pnl_result.Enabled = true; } else { /*txt_org.Enabled = false; txt_result.Enabled = false; btn_split.Enabled = false;*/ pnl_result.Enabled = false; } } protected void btn_split_Click(object sender, EventArgs e) { //定义字符数组ca, char[] ca; //清理文本框内容 txt_result.Text = ""; //如果文本框ORG中,有内容,则执行拆分动作 if (txt_org.Text != "") { ca = txt_org.Text.ToCharArray(); //将文本框ORG的值 赋值给字符数组变量 for (int i = 0; i < ca.Length; i++) //遍历字符数组中的每一个成员, { txt_result.Text += ca[i]+"\n"; } //将ca[i]的值写入多行文本框中,每写一个加一个换行符 "\n" } } }
相关文章推荐
- 【原创】Asp.net MVC 学习笔记之-为什么使用Html.TextBox方法会出现异常?
- Asp.net 学习 -服务器控件 -TextboxData
- ASP.NET学习笔记[8] - 梅花雨日历控件与textbox控件用法
- 一步步学习SPD2010--第十四章节--在Web页面使用控件(4)--使用ASP.NET验证控件
- ASP.NET中TextBox使用Ajax控件显示日期不全的问题解决方法
- ASP.NET中 TextBox控件使用 ReadOnly="true" 属性
- asp.net 学习之路之控件使用
- 黑马程序员_学习日记26_ASP.NET使用验证控件
- ASP.NET中 TextBox 文本输入框控件的使用方法
- ASP.NET中TextBox使用Ajax控件显示日期不全的问题解决方法
- asp.netAjax--TextBoxWateramrk控件使用
- ASP.NET中 TextBox控件使用 ReadOnly="true" 属性
- ASP.NET 学习笔记_01 广告控件的使用
- ASP.NET Ajax控件之使用二(TextBoxWatermarkExtender控件的使用)
- 一步步学习SPD2010--第十四章节--在Web页面使用控件(6)--测试ASP.NET表单
- Asp.Net Ajax--TextBoxWateramrk控件使用
- ASP.NET学习笔记四 控件使用
- 一步步学习SPD2010--第十四章节--在Web页面使用控件(4)--使用ASP.NET验证控件
- 学习笔记:ASP.NET TextBox 服务器控件源码
- 在学习ASP.NET中,GridView 控件的RowDataBound事件的使用详解