ProfileService.ValidatingProperties Event
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.
Occurs when a user's profile properties are set.
public:
static event EventHandler<System::Web::ApplicationServices::ValidatingPropertiesEventArgs ^> ^ ValidatingProperties;
public static event EventHandler<System.Web.ApplicationServices.ValidatingPropertiesEventArgs> ValidatingProperties;
member this.ValidatingProperties : EventHandler<System.Web.ApplicationServices.ValidatingPropertiesEventArgs>
Public Shared Custom Event ValidatingProperties As EventHandler(Of ValidatingPropertiesEventArgs)
Event Type
Examples
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");
}
}
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
AddHandler System.Web.ApplicationServices.ProfileService.ValidatingProperties, _
AddressOf ProfileService_ValidatingProperties
End Sub
Sub ProfileService_ValidatingProperties(ByVal sender As Object, ByVal e As System.Web.ApplicationServices.ValidatingPropertiesEventArgs)
If (String.IsNullOrEmpty(CType(e.Properties("FirstName"), String))) Then
e.FailedProperties.Add("FirstName")
End If
End Sub
Remarks
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.