<asp:textbox id="txtConfirmPassword" validationgroup="a" cssclass="textbox" textmode="Password" xmlns:asp="#unknown">
runat="server" Columns="20"></asp:textbox>
<asp:comparevalidator enableviewstate="false" display="None" validationgroup="a" xmlns:asp="#unknown">
ControlToValidate="txtConfirmPassword" runat="server" ErrorMessage="Your passwords do not match. Please type more carefully."
ID="CompareConfirm" ControlToCompare="txtNewPassword">
</asp:comparevalidator>
You can use Ajax "ValidatorCalloutExtender" to make the looks better
<ajaxToolkit:ValidatorCalloutExtender EnableViewState="false" ID="ValidatorCalloutExtender5"
TargetControlID="CompareConfirm" HighlightCssClass="validatorCalloutHighlight"
runat="server">
</ajaxToolkit:ValidatorCalloutExtender>
And for windows you can use this function to validate
Private Function ChangePassword() As Boolean
Try
Dim strMSG As String = ""
Dim intError As Integer = 0
If txtOldPass.Text.Trim.Equals("") Then
strMSG = "Old password can't be blank"
intError = 1
ElseIf txtNewPass.Text.Trim.Equals("") Then
strMSG = "New password can't be blank"
intError = 1
ElseIf txtConNewPass.Text.Trim.Equals("") Then
strMSG = "Confirm password can't be blank"
intError = 1
ElseIf Not txtOldPass.Text.Trim.Equals(strOLDPassword) Then
strMSG = "Old Password is incorrect"
intError = 1
ElseIf Not txtNewPass.Text.Trim.Equals(txtConNewPass.Text.Trim) Then
strMSG = " New Password and Confirm New Password do not Match"
intError = 1
ElseIf txtNewPass.Text.Trim.Length < 6 Then
strMSG = "New password can't be less than 6 characters"
intError = 1
ElseIf txtNewPass.Text.Trim.Equals(strOLDPassword) Then
strMSG = "New password can't be same as old password"
intError = 1
End If
If intError = 1 Then
MessageBox.Show(strMSG, "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return False
End If
Dim arrColName As New ArrayList
Dim arrRowData As New ArrayList
arrColName.Add("UM_VC30_Password")
arrRowData.Add(Encrypt(txtNewPass.Text.Trim))
Dim strSelectSQL As String
strSelectSQL = "select * from table where UM_IN4_Address_No_FK=" & cbUserName.SelectedValue
If objWS.Update(PropConString, "Table", strSelectSQL, arrColName, arrRowData, "frm_ChangePassword-ChangePassword-75") = True Then
MessageBox.Show("Password Changed Successfully", "Password Changed", MessageBoxButtons.OK, MessageBoxIcon.Information)
strOLDPassword = txtNewPass.Text.Trim
txtOldPass.Text = ""
txtNewPass.Text = ""
txtConNewPass.Text = ""
Return True
Else
MessageBox.Show("Please Try Later", "Try Later", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End If
Return True
Catch ex As Exception
XYZ.Logging.EventLogging.CreateLog("frm_ChangePassword", "ChangePassword-88", LogType.Application, LogSubType.Exception, ex.TargetSite.Attributes, ex.ToString, PropUserID, PropUserName)
End Try
End Function
And Button you can use this code
Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
ChangePassword()
End Sub