CreateUserWizard.OnCreatingUser Method

Raises the CreatingUser event prior to calling the membership provider to create the new user account.

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

'Declaration
Protected Overridable Sub OnCreatingUser ( _
	e As LoginCancelEventArgs _
)
'Usage
Dim e As LoginCancelEventArgs

Me.OnCreatingUser(e)
protected void OnCreatingUser (
	LoginCancelEventArgs e
)
protected function OnCreatingUser (
	e : LoginCancelEventArgs
)
Not applicable.

Parameters

e

A LoginCancelEventArgs containing the event data.

Use the OnCreatingUser method to do any processing required before sending the new user information to the CreateUser method of the membership provider specified in the MembershipProvider property. For example, you might set the user name field to all lowercase letters, or compare the e-mail address to a list of restricted addresses before allowing creation of the user account.

If you need to cancel the request to create the new user account, set the Cancel property of the LoginCancelEventArgs object passed as the e parameter to true.

Raising an event invokes the event handler through a delegate. For more information, see Handling and Raising Events.

The OnCreatingUser method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors: When overriding OnCreatingUser in a derived class, be sure to call the base class’s OnCreatingUser method so that registered delegates receive the event.

The following code example defines a custom CreateUserWizard control that uses the OnCreatingUser method to make the UserName property all lowercase.

Imports System
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
  <AspNetHostingPermission(System.Security.Permissions.SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class CustomCreateUserWizard
    Inherits CreateUserWizard
    
    Overloads Sub OnCreatingUser(ByVal e As LoginCancelEventArgs)
      Me.UserName.ToLower()
      MyBase.OnCreatingUser(e)
    End Sub    
    
  End Class
End Namespace

The following code example demonstrates a Web page that uses the CustomCreateUserWizard.

<%@ Page Language="VB"%>
<%@ Import namespace="Samples.AspNet.VB.Controls" %>

<!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)
    Dim createUser As New CustomCreateUserWizard
    Placeholder1.Controls.Add(createUser)
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateUserWizard.OnCreatingUser sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:placeholder id="Placeholder1" runat="server">
      </asp:placeholder>
    </div>
    </form>
</body>
</html>

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: