Export (0) Print
Expand All

HtmlInputPassword Class

Allows programmatic access to the HTML <input type= password> element on the server.

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

[ValidationPropertyAttribute("Value")]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class HtmlInputPassword : HtmlInputText, 
	IPostBackDataHandler
<asp:HtmlInputPassword />

The HtmlInputPassword class is derived from the HtmlInputText class and is used to create a single-line text box that allows the user to enter a password. When using the HtmlInputPassword control, the Value property is posted to the server each time the form is submitted. The Value property for the HtmlInputPassword control is not persisted in view state.

The MaxLength property specifies the maximum number of characters that can be entered in the text box. The Size property allows you to specify the width of the text box. Use the Value property to determine the value entered in the text box by the user. The HtmlInputPassword control provides a ServerChange event that is raised when the Value property changes values between posts to the server. This allows you to create an event handler that performs a custom set of instructions each time the event is raised.

NoteNote:

The HtmlInputPassword control does not provide a built-in way to post back to the server. You must provide another control on the Web page that supports posting back to the server, such as an HtmlButton or an HtmlInputSubmit control.

For a list of initial property values for an instance of HtmlInputPassword, see the HtmlInputPassword constructor.

The following code example demonstrates how to use the <input type=text>, <input type=password>, and <input type=submit> HTML controls declaratively on a Web Forms page.

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

<!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 runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        &nbsp;&nbsp;

        <p></p><div>Username</div> <br />
        <input type="text" runat="server" />

        <p></p><div>Password</div> <br />
        <input type="password" runat="server" />

        <p></p><input type="submit" runat="server" value="Submit" />

    </form>
  </body>
</html>

The following code example demonstrates how to add the same HTML controls programmatically during a call to the Page_Load method.

<%@ 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>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft