ChangePassword.DisplayUserName Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value indicating whether the ChangePassword control should display the UserName control and label.
public:
virtual property bool DisplayUserName { bool get(); void set(bool value); };
public virtual bool DisplayUserName { get; set; }
member this.DisplayUserName : bool with get, set
Public Overridable Property DisplayUserName As Boolean
Property Value
true
if the ChangePassword control should display the UserName; otherwise, false
. The default is false
.
Examples
The following code example shows how to set the DisplayUserName property to display the UserName control to users who are not logged on to the Web site.
<%@ 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">
void Page_Load(object sender, EventArgs e )
{
if (Context.User.Identity.IsAuthenticated)
{
Changepassword1.DisplayUserName = false;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ChangePassword.DisplayUserName sample.</title>
</head>
<body>
<form id="form1" runat="server">
<div>
User's login status: <asp:loginstatus id="status" runat="server" /><br />
<asp:changepassword id="Changepassword1" runat="server" displayusername="true" />
</div>
</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">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Context.User.Identity.IsAuthenticated Then
changepassword1.DisplayUserName = False
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ChangePassword.DisplayUserName sample.</title>
</head>
<body>
<form id="form1" runat="server">
<div>
User's login status: <asp:loginstatus id="status" runat="server" /><br />
<asp:changepassword id="Changepassword1" runat="server" displayusername="true" />
</div>
</form>
</body>
</html>
Remarks
In order to change their password, users must be authenticated by the membership provider. To allow users who are not logged on to change their password, or to be authenticated by the membership provider with a different user account and then change the password for that account, the ChangePassword control can display a TextBox control to accept the user name.
You must set the DisplayUserName property to true
if the ChangePassword control will be displayed to users who are not logged on; otherwise, the user will not be able to specify a user name.
Applies to
See also
- ASP.NET Login Controls Overview
- Customizing Appearance and Behavior of the ASP.NET Login Controls
- ASP.NET Web Server Controls Templates
- How to: Display Different Information to Anonymous and Logged In Users
- Web Site Administration Tool Security Tab
- Securing Login Controls
- Basic Security Practices for Web Applications
- Securing Membership