Export (0) Print
Expand All

PasswordRecovery.UserName Property

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

Gets or sets the text that appears in the User Name text box.

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

[LocalizableAttribute(true)] 
public virtual string UserName { get; set; }
/** @property */
public String get_UserName ()

/** @property */
public void set_UserName (String value)

public function get UserName () : String

public function set UserName (value : String)

Property Value

The user name entered by the user. The default value is Empty.

The UserName property contains the user name entered by the user, or Empty if the user has not entered a name. The UserName property is used only in the UserName view.

The UserName property is saved in the PasswordRecovery control's control state to preserve the values between round trips to the server even when view state is turned off for the page. PasswordRecovery control properties represented by text boxes, such as UserName, are accessible during all phases of the page life cycle. The control will pick up any changes made by the end user by means of the TextChanged event triggered by the textboxes.

The style settings in the TextBoxStyle property define the appearance of the text in the UserName property.

When you assign a template to the UserName property to display the UserName view, the UserName property is assigned the value entered in a required TextBox control with the ID property set to "UserName".

The value of this property, when set, can be saved automatically to a resource file by using a designer tool. For more information, see LocalizableAttribute and ASP.NET Globalization and Localization.

The following code example changes the UserName property for a specific membership provider.

<%@ page language="C#" %>

<script runat="server"> 

    void PasswordRecovery1_VerifyingUser(Object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
    {
	      DropDownList provider = ((DropDownList)PasswordRecovery1.FindControl("LoginProvider"));

        PasswordRecovery1.MembershipProvider = provider.SelectedValue;
        if (PasswordRecovery1.MembershipProvider != "Default")
        {
          PasswordRecovery1.UserName = String.Format("{0}\\{1}",
            PasswordRecovery1.MembershipProvider, PasswordRecovery1.UserName);    
        }         

    }
    
    void PasswordRecovery1_VerifyingAnswer(Object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
    {
        PasswordRecovery1.UserName = String.Format("{0}\\{1}",
          PasswordRecovery1.MembershipProvider, PasswordRecovery1.UserName);
    }  
    
</script>

<html>
  <body>
    <form runat="server">
      <asp:passwordrecovery id="PasswordRecovery1" 
        runat="server" 
        onverifyinguser="PasswordRecovery1_VerifyingUser"
        onverifyinganswer="PasswordRecovery1_VerifyingAnswer">
        <usernametemplate>
          <table border="0">
            <tr>
              <td align="Center" colspan="2">Forgot Your Password?</td>
            </tr>
            <tr>
              <td align="Center" colspan="2">Enter your User Name to receive your password.</td>
            </tr>
            <tr>
              <td>Log in domain:</td>
              <td>
                <asp:dropdownlist id="LoginProvider" runat="server">
                  <asp:listitem value="Default">Default</asp:listitem>
                  <asp:listitem value="Administration">Administration</asp:listitem>
                  <asp:listitem value="Editorial">Editorial</asp:listitem>
                  <asp:listitem value="Finance">Finance</asp:listitem>
                  <asp:listitem value="Marketing">Marketing</asp:listitem>
                </asp:dropdownlist>
              </td>
            </tr>
            <tr>
              <td align="Right">User Name:</td>
              <td>
                <asp:textbox runat="server" id="UserName"></asp:textbox>
                <asp:requiredfieldvalidator runat="server" 
                  controltovalidate="UserName" 
                  errormessage="User Name." 
                  id="UserNameRequired">
                  *
                </asp:requiredfieldvalidator>
              </td>
            </tr>
            <tr>
              <td align="Right" colspan="2">
                <asp:button runat="server" 
                  commandname="Submit" 
                  text="Submit" 
                  id="Button">
                </asp:button>
              </td>
            </tr>
            <tr>
              <td colspan="2" style="color:Red;">
                <asp:literal runat="server" id="FailureText"></asp:literal>
              </td>
            </tr>
          </table>
        </usernametemplate>
      </asp:passwordrecovery>
    </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