Share via


HtmlInputText 建構函式

定義

初始化 HtmlInputText 類別的新執行個體。

多載

HtmlInputText()

使用預設值,初始化 HtmlInputText 類別的新執行個體。

HtmlInputText(String)

使用指定的輸入控制項型別來初始化 HtmlInputText 類別的新執行個體。

HtmlInputText()

使用預設值,初始化 HtmlInputText 類別的新執行個體。

public:
 HtmlInputText();
public HtmlInputText ();
Public Sub New ()

範例

<%@ 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" >
   <script runat="server" >
  
      void Page_Load(Object sender, EventArgs e)
      {

         // Create an HtmlInputText control.
         HtmlInputText text = new HtmlInputText();
         text.Value = "Enter a value.";
         text.MaxLength = 20;
         text.Size = 22;
 
         // Add the control to the Controls collection of the 
         // PlaceHolder control.
         Place.Controls.Clear();
         Place.Controls.Add(text);
         
      }
  
   </script>
  
<head runat="server">
    <title> HtmlInputText Constructor Example </title>
</head>
<body>

   <form id="form1" runat="server">
  
      <h3> HtmlInputText Constructor Example </h3> 
  
      <asp:PlaceHolder id="Place" 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" >
   <script runat="server" >
  
      Sub Page_Load(sender As Object, e As EventArgs)

         ' Create an HtmlInputText control.
         Dim text As HtmlInputText = New HtmlInputText()
         text.Value = "Enter a value."
         text.MaxLength = 20
         text.Size = 22
 
         ' Add the control to the Controls collection of the 
         ' PlaceHolder control.
         Place.Controls.Clear()
         Place.Controls.Add(text)
         
      End Sub
  
   </script>
  
<head runat="server">
    <title> HtmlInputText Constructor Example </title>
</head>
<body>

   <form id="form1" runat="server">
  
      <h3> HtmlInputText Constructor Example </h3> 
  
      <asp:PlaceHolder id="Place" runat="server"/>
  
   </form>

</body>
</html>

備註

使用此建構函式,使用預設值來建立和初始化 控制項的新實例 HtmlInputText 。 它會建立 text 類型文字方塊控制項。

下表顯示 實例 HtmlInputText 的初始屬性值。

屬性 初始值
Type 「text」 常值字串。

另請參閱

適用於

HtmlInputText(String)

使用指定的輸入控制項型別來初始化 HtmlInputText 類別的新執行個體。

public:
 HtmlInputText(System::String ^ type);
public HtmlInputText (string type);
new System.Web.UI.HtmlControls.HtmlInputText : string -> System.Web.UI.HtmlControls.HtmlInputText
Public Sub New (type As String)

參數

type
String

輸入控制項的型別。

範例

<%@ 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" >
   <script runat="server" >
  
      void Page_Load(Object sender, EventArgs e)
      {

         // Create an HtmlInputText control.
         HtmlInputText text = new HtmlInputText("password");
         text.MaxLength = 20;
         text.Size = 22;
 
         // Add the control to the Controls collection of the 
         // PlaceHolder control.
         Place.Controls.Clear();
         Place.Controls.Add(text);
         
      }

      void Button_Click(Object sender, EventArgs e)
      {

         // Insert secure authentication here.
         // Make sure to use SSL to secure the connection.

      }
  
   </script>
  
<head runat="server">
    <title> HtmlInputText Constructor Example </title>
</head>
<body>

   <form id="form1" runat="server">
  
      <h3> HtmlInputText Constructor Example </h3> 
  
      Enter your password: <br />
      <asp:PlaceHolder id="Place" runat="server"/>

      <br /><br />
 
      <input type="submit"
             value="Submit"
             onserverclick="Button_Click" 
             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" >
   <script runat="server" >
  
      Sub Page_Load(sender As Object, e As EventArgs)

         ' Create an HtmlInputText control.
         Dim text As HtmlInputText = New HtmlInputText("password")
         text.MaxLength = 20
         text.Size = 22
 
         ' Add the control to the Controls collection of the 
         ' PlaceHolder control.
         Place.Controls.Clear()
         Place.Controls.Add(text)
         
      End Sub

      Sub Button_Click(sender As Object, e As EventArgs)

         ' Insert secure authentication here.
         ' Make sure to use SSL to secure the connection.

      End Sub
  
   </script>
  
<head runat="server">
    <title> HtmlInputText Constructor Example </title>
</head>
<body>

   <form id="form1" runat="server">
  
      <h3> HtmlInputText Constructor Example </h3> 
  
      Enter your password: <br />
      <asp:PlaceHolder id="Place" runat="server"/>

      <br /><br />
 
      <input type="submit"
             value="Submit"
             onserverclick="Button_Click" 
             runat="server"/> 
  
   </form>

</body>
</html>

備註

使用此建構函式,使用指定的輸入控制項類型來建立和初始化 控制項的新實例 HtmlInputText 。 它可讓您建立特定類型的文字方塊控制項,例如 passwordpassword目前僅支援 或 text 類型。 此建構函式是設計成可讓您建立其他文字方塊類型,前提是這些類型可供使用。

下表顯示 實例 HtmlInputText 的初始屬性值。

屬性 初始值
Type type 參數的值。

注意

雖然您可以使用這個建構函式來建立 text 類型文字方塊控制項,但通常會改用無參數建構函式。

另請參閱

適用於