.
.aspx代码例如以下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TextBox_test.aspx.cs" Inherits="TextBox_test" %>
<!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">
<title></title>
</head>
<body>
<form id="form1" runat="server">
这是一个HTML input控件:<input id="Text1" type="text" /><br />
这是一个ASP标准服务器控件:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
这是一个带有RUNAT属性的HTML控件:<input id="Text2" type="text" runat="server" /><br />
<asp:Button ID="Button1" runat="server" Text="更改第一个文本框的值(后台程序无法做到)"
/>
<br />
<asp:Button ID="Button2" runat="server" Text="更改第二个文本框的值"
onclick="Button2_Click" />
<br />
<asp:Button ID="Button3" runat="server" Text="更改第三个文本框的值"
onclick="Button3_Click" />
</form>
</body>
</html>
.aspx.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 TextBox_test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = DateTime.Now.ToLongDateString(); } protected void Button3_Click(object sender, EventArgs e) { Text2.Value = DateTime.Now.ToString(); } }
效果图吐下:
.aspx代码例如以下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sample 3-02.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>文本框的多种表现形式</h3>
<div class="d1">单行文本框:
<asp:TextBox ID="txt_s" runat="server" Enabled="false" ></asp:TextBox>
<asp:Button ID="btn_reads" runat="server" Text="读取内容并显示"
onclick="btn_reads_Click" />
</div>
<div class="d1">多行文本框:
<asp:TextBox ID="txt_m" runat="server" TextMode="MultiLine"
Height="200px" Width="200px" ></asp:TextBox>
<asp:Button ID="btn_readm" runat="server" Text="读取内容并显示"
onclick="btn_readm_Click" />
</div>
<div class="d1">password文本框:
<asp:TextBox ID="txt_p" runat="server" TextMode="Password" ></asp:TextBox>
<asp:Button ID="btn_readp" runat="server" Text="读取内容并显示"
onclick="btn_readp_Click" />
</div>
<div class="d1">HTML文本框:
<input id="txt_html" type="text" runat="server" />
<asp:Button ID="btn_readhtml" runat="server" Text="读取内容并显示"
onclick="btn_readhtml_Click" />
</div>
<br /> <br /> <br />
显示结果的层:
<div id="div_result" runat="server" > </div>
</div>
</form>
</body>
</html>
.aspx.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 btn_reads_Click(object sender, EventArgs e) { //div的InnerText属性调用;请注意非常多其它的HTML控件都有InnerText属性。如<p>,<span>,<td>... div_result.InnerText = txt_s.Text; } protected void btn_readhtml_Click(object sender, EventArgs e) { div_result.InnerText = txt_html.Value; } protected void btn_readm_Click(object sender, EventArgs e) { div_result.InnerText = txt_m.Text; } protected void btn_readp_Click(object sender, EventArgs e) { div_result.InnerText = txt_p.Text; } }