Export (0) Print
Expand All

ProfileService.ValidatingProperties Event

Occurs when a user's profile properties are set.

Namespace:  System.Web.ApplicationServices
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public static event EventHandler<ValidatingPropertiesEventArgs> ValidatingProperties

You can create an event handler for the ValidatingProperties event to validate property values or to dynamically change their values. The ValidatingProperties event is raised when the SetPropertiesForCurrentUser method is called. If the value for a property fails validation, add that property to the FailedProperties collection of the ValidatingPropertiesEventArgs class. Any properties that are in the FailedProperties collection will not be saved to the user profile.

You can add and register the event handler in the Global.asax file.

The following example shows an event handler for the ValidatingProperties event. When the value passed for FirstName property is empty or null, the FirstName property is added to the FailedProperties collection.

void Application_Start(object sender, EventArgs e) 
{
    System.Web.ApplicationServices.ProfileService.ValidatingProperties += new EventHandler<System.Web.ApplicationServices.ValidatingPropertiesEventArgs>(ProfileService_ValidatingProperties);
}

void ProfileService_ValidatingProperties(object sender, System.Web.ApplicationServices.ValidatingPropertiesEventArgs e)
{
    if (String.IsNullOrEmpty((string)e.Properties["FirstName"]))
    {
        e.FailedProperties.Add("FirstName");
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft