HtmlInputPassword 构造函数

定义

使用默认值初始化 HtmlInputPassword 类的新实例。

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

示例

下面的代码示例演示如何使用默认构造函数以编程方式将控件HtmlInputSubmit添加到HtmlInputTextHtmlInputPasswordWeb Forms页,以创建简单的登录屏幕。

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  
  protected void page_load(object sender, EventArgs e)
  {
    if (IsPostBack)
    {
      // Add code to process the Login.
    }
  }

  protected void Page_Init(object sender, EventArgs e)
  {
    HtmlInputText userText = new HtmlInputText();
    userText.MaxLength = 20;
    Placeholder1.Controls.Add(userText);

    HtmlInputPassword passwordText = new HtmlInputPassword();
    passwordText.MaxLength = 20;
    Placeholder2.Controls.Add(passwordText);

    HtmlInputSubmit submitButton = new HtmlInputSubmit();
    submitButton.Value = "Submit";
    Placeholder3.Controls.Add(submitButton);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <table cellpadding="2">
        <tr>
        <td>User Name
            <asp:placeholder
                runat="server"
                id="Placeholder1" />
        </td></tr>
        <tr>
        <td>Password
            <asp:placeholder
                runat="server"
                id="Placeholder2" />
        </td></tr>
        <tr><td><asp:placeholder
                runat="server"
                id="Placeholder3" />
        </td></tr>
      </table>
    </form>
  </body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    
    If (IsPostBack) Then
      ' Add code to process the Login.
    End If

  End Sub

  Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
    
    Dim userText As HtmlInputText = New HtmlInputText
    userText.MaxLength = 20
    Placeholder1.Controls.Add(userText)

    Dim passwordText As HtmlInputPassword = New HtmlInputPassword
    passwordText.MaxLength = 20
    Placeholder2.Controls.Add(passwordText)

    Dim submitButton As HtmlInputSubmit = New HtmlInputSubmit
    submitButton.Value = "Submit"
    Placeholder3.Controls.Add(submitButton)

  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" runat="server">

      <table cellpadding="2">
        <tr>
        <td>User Name
            <asp:placeholder
                runat="server"
                id="Placeholder1" />
        </td></tr>
        <tr>
        <td>Password
            <asp:placeholder
                runat="server"
                id="Placeholder2" />
        </td></tr>
        <tr><td><asp:placeholder
                runat="server"
                id="Placeholder3" />
        </td></tr>
      </table>
    </form>
  </body>
</html>

注解

使用此构造函数使用默认值创建和初始化控件的新实例 HtmlInputPassword 。 它创建一个 password 类型文本框控件。

下表显示了实例 HtmlInputPassword的初始属性值。

properties 初始值
Type “password”文本字符串。

适用于