Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

PasswordRecovery.VerifyingUser Event

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

Occurs before the user name is validated by the membership provider.

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

public event LoginCancelEventHandler VerifyingUser
/** @event */
public void add_VerifyingUser (LoginCancelEventHandler value)

/** @event */
public void remove_VerifyingUser (LoginCancelEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

The VerifyingUser event is raised on the server before the user name is submitted to the membership provider to determine whether the user name is valid. Use this event to perform any preprocessing needed on the user name, such as converting it to all uppercase or lowercase letters, or verifying that the user name is in a particular format, such as an e-mail address.

The PasswordRecovery control first raises the VerifyingUser event, and then uses the membership provider specified in the MembershipProvider property to determine whether the user name entered is a valid user name for the Web site. If it is valid, and the membership provider supports password question and answer, the password verification question is returned from the Web site and the PasswordRecovery control displays the Question view. If the user name is not valid, the text in the GeneralFailureText property is displayed in the UserName view so that the user can enter a different user name.

If the membership provider does not support password question and answer, the SendingMail event is raised and e-mail is sent to the user with the new or recovered password.

For more information about handling events, see Events and Delegates.

The following code example uses the VerifyingUser event to check whether the submitted user name is formatted as a valid e-mail address. If the user name is not formatted properly, the UserNameInstructionText property is changed to show the error.

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

<script runat="server">

bool IsValidEmail(string strIn)
{
    // Return true if strIn is in valid e-mail format.
    return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); 
}

void PasswordRecovery1_VerifyingUser(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
    if (!IsValidEmail(PasswordRecovery1.UserName))
    {
        PasswordRecovery1.UserNameInstructionText = "You must enter a valid e-mail address.";
        e.Cancel = true;
    }
    else
    {
            PasswordRecovery1.UserNameInstructionText = "Enter your User Name to receive your password.";
    }
}

</script>

<html>
  <body>
    <form runat="server">
      <asp:passwordrecovery id="PasswordRecovery1" 
        runat="server" 
        onverifyinguser="PasswordRecovery1_VerifyingUser">
      </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:
© 2015 Microsoft