TextBox.TextMode 属性
定义
public:
virtual property System::Web::UI::WebControls::TextBoxMode TextMode { System::Web::UI::WebControls::TextBoxMode get(); void set(System::Web::UI::WebControls::TextBoxMode value); };
public virtual System.Web.UI.WebControls.TextBoxMode TextMode { get; set; }
[System.Web.UI.Themeable(false)]
public virtual System.Web.UI.WebControls.TextBoxMode TextMode { get; set; }
member this.TextMode : System.Web.UI.WebControls.TextBoxMode with get, set
[<System.Web.UI.Themeable(false)>]
member this.TextMode : System.Web.UI.WebControls.TextBoxMode with get, set
Public Overridable Property TextMode As TextBoxMode
属性值
TextBoxMode 枚举值之一。One of the TextBoxMode enumeration values. 默认值是 SingleLine。The default value is SingleLine.
- 属性
例外
指定的模式不是 TextBoxMode 枚举值之一。The specified mode is not one of the TextBoxMode enumeration values.
示例
下面的代码示例演示如何使用 TextMode 属性来指定多行文本框。The following code example demonstrates how to use the TextMode property to specify a multiline text box.
重要
此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。This example has a text box that accepts user input, which is a potential security threat. 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述。For more information, see Script Exploits Overview.
<%@ Page Language="C#" AutoEventWireup="True" %>
<!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>
<title> MultiLine TextBox Example </title>
<script runat="server">
protected void SubmitButton_Click(Object sender, EventArgs e)
{
Message.Text = "Thank you for your comment: <br />" + Comment.Text;
}
protected void Check_Change(Object sender, EventArgs e)
{
Comment.Wrap = WrapCheckBox.Checked;
Comment.ReadOnly = ReadOnlyCheckBox.Checked;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> MultiLine TextBox Example </h3>
Please enter a comment and click the submit button.
<br /><br />
<asp:TextBox ID="Comment"
TextMode="MultiLine"
Columns="50"
Rows="5"
runat="server"/>
<br />
<asp:RequiredFieldValidator
ID="Value1RequiredValidator"
ControlToValidate="Comment"
ErrorMessage="Please enter a comment.<br />"
Display="Dynamic"
runat="server"/>
<asp:CheckBox ID="WrapCheckBox"
Text="Wrap Text"
Checked="True"
AutoPostBack="True"
OnCheckedChanged="Check_Change"
runat="server"/>
<asp:CheckBox ID="ReadOnlyCheckBox"
Text="ReadOnly"
Checked="False"
AutoPostBack="True"
OnCheckedChanged="Check_Change"
runat="server"/>
<asp:Button ID="SubmitButton"
Text="Submit"
OnClick="SubmitButton_Click"
runat="server"/>
<hr />
<asp:Label ID="Message"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!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>
<title> MultiLine TextBox Example </title>
<script runat="server">
Protected Sub SubmitButton_Click(sender As Object, e As EventArgs )
Message.Text = "Thank you for your comment: <br />" + Comment.Text
End Sub
Protected Sub Check_Change(sender As Object, e As EventArgs )
Comment.Wrap = WrapCheckBox.Checked
Comment.ReadOnly = ReadOnlyCheckBox.Checked
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> MultiLine TextBox Example </h3>
Please enter a comment and click the submit button.
<br /><br />
<asp:TextBox ID="Comment"
TextMode="MultiLine"
Columns="50"
Rows="5"
runat="server"/>
<br />
<asp:RequiredFieldValidator
ID="Value1RequiredValidator"
ControlToValidate="Comment"
ErrorMessage="Please enter a comment.<br />"
Display="Dynamic"
runat="server"/>
<asp:CheckBox ID="WrapCheckBox"
Text="Wrap Text"
Checked="True"
AutoPostBack="True"
OnCheckedChanged="Check_Change"
runat="server"/>
<asp:CheckBox ID="ReadOnlyCheckBox"
Text="ReadOnly"
Checked="False"
AutoPostBack="True"
OnCheckedChanged="Check_Change"
runat="server"/>
<asp:Button ID="SubmitButton"
Text="Submit"
OnClick="SubmitButton_Click"
runat="server"/>
<hr />
<asp:Label ID="Message"
runat="server"/>
</form>
</body>
</html>
注解
使用 TextMode 属性指定控件的显示方式 TextBox 。Use the TextMode property to specify how a TextBox control is displayed. 三个常见选项是单行、多行或密码文本框。Three common options are single-line, multiline, or password text box.
当 TextBox 控件处于多行模式时,您可以通过设置属性来控制所显示的行数 Rows 。When the TextBox control is in multiline mode, you can control the number of rows displayed by setting the Rows property. 还可以通过设置属性来指定文本是否应换行 Wrap 。You can also specify whether the text should wrap by setting the Wrap property.
如果 TextBox 控件处于密码模式,则在该控件中输入的所有字符都将被屏蔽。If the TextBox control is in password mode, all characters entered in the control are masked.
无法通过主题或样式表主题设置此属性。This property cannot be set by themes or style sheet themes. 有关详细信息,请参阅 ThemeableAttribute 和 ASP.NET 主题和外观。For more information, see ThemeableAttribute and ASP.NET Themes and Skins.