PasswordTextBoxValidator Class
Represents the password text box validation function.
System.Object
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.Label
System.Web.UI.WebControls.BaseValidator
System.Web.UI.WebControls.RequiredFieldValidator
Microsoft.SharePoint.WebControls.InputFormRequiredFieldValidator
Microsoft.SharePoint.WebControls.PasswordTextBoxValidator
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.Label
System.Web.UI.WebControls.BaseValidator
System.Web.UI.WebControls.RequiredFieldValidator
Microsoft.SharePoint.WebControls.InputFormRequiredFieldValidator
Microsoft.SharePoint.WebControls.PasswordTextBoxValidator
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
PasswordTextBoxValidator
Description
The Microsoft.SharePoint.WebControls.PasswordTextBoxValidator class inherits from Microsoft.SharePoint.WebControls.InputFormRequiredFieldValidator, providing a method to validate entries into Microsoft.SharePoint.WebControls.PasswordTextBox input controls.
First the control will override the System.Web.UI.WebControls.RequiredFieldValidator.EvaluateIsValid() method in order to supply type dependent validation checking. Within the EvalutateisValid() method, it will use System.Web.UI.Control.FindControl() to get the target Control representation, then cast it to Microsoft.SharePoint.WebControls.PasswordTextBox in order to expose the relevant type. Following, it will check two properties of the PasswordTextBox. EditingPreviouslySavedPassword is firstly checked which queries the ViewState for whether the password was previously changed and saved. The PasswordWasChanged property represents whether the password has been adjusted.
It should be noted that this control can only be coupled with the Microsoft.SharePoint.WebControls.PasswordTextBox control due to casting considerations. It is useful to use the inherit PasswordTextBox.PasswordChanged event to call the validation.
The Usage Scenario
You typically use the PasswordTextBoxValidator control when building custom EditorParts to allow users to enter passwords into WebPart properties, or when you have password input controls that require identity validation into orphaned systems.
The following code samples show how you might use the PasswordTextBoxValidator with event handling from the PasswordTextBox control:
C# Code Example
protected override void CreateChildControls()
{
PasswordTextBox password = new PasswordTextBox();
password.PasswordChanged += password_PasswordChanged;
Controls.Add(password);
}
void password_PasswordChanged(object sender, EventArgs e)
{
PasswordTextBox password = (PasswordTextBox) sender;
PasswordTextBoxValidator validator = new PasswordTextBoxValidator();
validator.ControlToValidate = FindControl(password.ClientID).ToString();
Controls.Add(validator);
}
Visual Basic .NET Code Example
Protected Overloads Overrides Sub CreateChildControls()
Dim password As New PasswordTextBox()
password.PasswordChanged += password_PasswordChanged
Controls.Add(password)
End Sub
Private Sub password_PasswordChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim password As PasswordTextBox = DirectCast(sender, PasswordTextBox)
Dim validator As New PasswordTextBoxValidator()
validator.ControlToValidate = FindControl(password.ClientID).ToString()
Controls.Add(validator)
End Sub
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
The Microsoft.SharePoint.WebControls.PasswordTextBoxValidator class inherits from Microsoft.SharePoint.WebControls.InputFormRequiredFieldValidator, providing a method to validate entries into Microsoft.SharePoint.WebControls.PasswordTextBox input controls.
First the control will override the System.Web.UI.WebControls.RequiredFieldValidator.EvaluateIsValid() method in order to supply type dependent validation checking. Within the EvalutateisValid() method, it will use System.Web.UI.Control.FindControl() to get the target Control representation, then cast it to Microsoft.SharePoint.WebControls.PasswordTextBox in order to expose the relevant type. Following, it will check two properties of the PasswordTextBox. EditingPreviouslySavedPassword is firstly checked which queries the ViewState for whether the password was previously changed and saved. The PasswordWasChanged property represents whether the password has been adjusted.
It should be noted that this control can only be coupled with the Microsoft.SharePoint.WebControls.PasswordTextBox control due to casting considerations. It is useful to use the inherit PasswordTextBox.PasswordChanged event to call the validation.
The Usage Scenario
You typically use the PasswordTextBoxValidator control when building custom EditorParts to allow users to enter passwords into WebPart properties, or when you have password input controls that require identity validation into orphaned systems.
The following code samples show how you might use the PasswordTextBoxValidator with event handling from the PasswordTextBox control:
C# Code Example
protected override void CreateChildControls()
{
PasswordTextBox password = new PasswordTextBox();
password.PasswordChanged += password_PasswordChanged;
Controls.Add(password);
}
void password_PasswordChanged(object sender, EventArgs e)
{
PasswordTextBox password = (PasswordTextBox) sender;
PasswordTextBoxValidator validator = new PasswordTextBoxValidator();
validator.ControlToValidate = FindControl(password.ClientID).ToString();
Controls.Add(validator);
}
Visual Basic .NET Code Example
Protected Overloads Overrides Sub CreateChildControls()
Dim password As New PasswordTextBox()
password.PasswordChanged += password_PasswordChanged
Controls.Add(password)
End Sub
Private Sub password_PasswordChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim password As PasswordTextBox = DirectCast(sender, PasswordTextBox)
Dim validator As New PasswordTextBoxValidator()
validator.ControlToValidate = FindControl(password.ClientID).ToString()
Controls.Add(validator)
End Sub
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
- 5/24/2010
- Adam Buenz - MVP