Export (0) Print
Expand All

HtmlInputPassword Constructor

Note: This constructor is new in the .NET Framework version 2.0.

Initializes a new instance of the HtmlInputPassword class using default values.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

public HtmlInputPassword ()
public HtmlInputPassword ()
public function HtmlInputPassword ()

Use this constructor to create and initialize a new instance of the HtmlInputPassword control using default values. It creates a password type text box control.

The following table shows the initial property value for an instance of HtmlInputPassword.

Property

Initial Value

Type

The "password" literal string.

The following code example demonstrates how to programmatically add HtmlInputText, HtmlInputPassword, and HtmlInputSubmit controls to a Web Forms page using default constructors to create a simple login screen.

<%@ 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" >
  <body>
    <form 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="VJ#" %>

<!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, System.EventArgs e)
  {
    if (get_IsPostBack())
    {
      // Add code to process the Login.
    }

  }

  protected void Page_Init(Object sender, EventArgs e)
  {
    HtmlInputText userText = new HtmlInputText();
    userText.set_MaxLength(20);
    Placeholder1.get_Controls().Add(userText);

    HtmlInputPassword passwordText = new HtmlInputPassword();
    passwordText.set_MaxLength(20);
    Placeholder2.get_Controls().Add(passwordText);

    HtmlInputSubmit submitButton = new HtmlInputSubmit();
    submitButton.set_Value("Submit");
    Placeholder3.get_Controls().Add(submitButton);


  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <body>
    <form 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft