CreateUserWizard.OnCreatingUser Method (LoginCancelEventArgs)


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)

protected virtual void OnCreatingUser(
	LoginCancelEventArgs e


Type: System.Web.UI.WebControls.LoginCancelEventArgs

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.

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls {
  [AspNetHostingPermission(System.Security.Permissions.SecurityAction.Demand,Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand,Level = AspNetHostingPermissionLevel.Minimal)]
  public class CustomCreateUserWizard : CreateUserWizard {

    protected override void OnCreatingUser(LoginCancelEventArgs e) {

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

<%@ Page Language="C#"%>
<%@ Import namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void Page_Load(object sender, EventArgs e)
    CustomCreateUserWizard createUser = new CustomCreateUserWizard();


<html xmlns="" >
<head id="Head1" runat="server">
    <title>CreateUserWizard.OnCreatingUser sample</title>
    <form id="form1" runat="server">
      <asp:placeholder id="Placeholder1" runat="server">

.NET Framework
Available since 2.0
Return to top