TextBox.TextMode 屬性

定義

取得或設定 TextBox 控制項的行為模式 (例如單行、多行或密碼)。Gets or sets the behavior mode (such as, single-line, multiline, or password) of the TextBox control.

public:
 virtual property System::Web::UI::WebControls::TextBoxMode TextMode { System::Web::UI::WebControls::TextBoxMode get(); void set(System::Web::UI::WebControls::TextBoxMode value); };
[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
Public Overridable Property TextMode As TextBoxMode

屬性值

其中一個 TextBoxMode 列舉值。One of the TextBoxMode enumeration values. 預設值為 SingleLineThe 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 Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。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"/>

      &nbsp;&nbsp;

      <asp:CheckBox ID="ReadOnlyCheckBox"
           Text="ReadOnly"
           Checked="False"
           AutoPostBack="True"
           OnCheckedChanged="Check_Change"
           runat="server"/>

      &nbsp;&nbsp;

      <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"/>

      &nbsp;&nbsp;

      <asp:CheckBox ID="ReadOnlyCheckBox"
           Text="ReadOnly"
           Checked="False"
           AutoPostBack="True"
           OnCheckedChanged="Check_Change"
           runat="server"/>

      &nbsp;&nbsp;

      <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.

當 @no__t 0 控制項處於多行模式時,您可以藉由設定 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.

如果 @no__t 0 控制項在密碼模式中,則在控制項中輸入的所有字元都會加上遮罩。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. 如需詳細資訊,請參閱 ThemeableAttributeASP.NET 主題和外觀For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

適用於

另請參閱