Hi rani,
Check this example. Now please take its reference and correct your code.
In the sample i am checking with hardcode value. You need to check with your database record.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.8/angular.js"></script>
<script type="text/javascript">
var app = angular.module("MyApp", []);
app.controller("MyController", ['$scope', '$http', '$window', function ($scope, $http, $window) {
$scope.IsVisible = false;
$scope.Save = function () {
if (!$scope.IsVisible) {
$http.post("Default.aspx/ResetPassword", JSON.stringify({ UserName: $scope.username, OldPassword: $scope.oldpassword, NewPassword: $scope.newpassword })
).then(function (response) {
$window.alert(response.data.d);
}, function error(response) {
$window.alert(response.responseText);
});
}
}
$scope.Compare = function () {
if ($scope.newpassword != $scope.confirmpassword) {
$scope.IsVisible = true;
} else {
$scope.IsVisible = false;
}
}
} ]);
</script>
<div ng-app="MyApp" ng-controller="MyController">
<div class="container">
<div class="form-horizontal ">
<div class="row">
<div class="col-md-3">
<label for="UserName">
User Name</label>
<input type="text" name="username" class="form-control" ng-model="username" />
</div>
<div class="col-md-3">
<label for="OldPassword">
Old Password</label>
<input type="text" name="oldpassword" class="form-control" ng-model="oldpassword" />
</div>
<div class="col-md-3">
<label for="NewPassword">
New Password</label>
<input type="text" name="newpassword" class="form-control" ng-model="newpassword" />
</div>
<div class="col-md-3">
<label for="ConfirmPassword">
Confirm Password</label>
<input type="text" name="confirmpassword" class="form-control" ng-model="confirmpassword"
ng-keyup="Compare()" />
<div ng-show="IsVisible" class="help-block" style="color: red">
New and Confirm Password do not match</div>
</div>
</div>
<div class="form-group" style="width: 120%; padding: 10px;">
<div class="col-md-offset-2 col-md-5">
<button type="button" class="btn btn-success btn-sm" ng-model="IsVisible" ng-click="Save()">
Save</button>
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
Namespaces
C#
using System.Web.Services;
VB.Net
Imports System.Web.Services
Code
C#
[WebMethod]
public static string ResetPassword(string UserName, string OldPassword, string NewPassword)
{
// Get old password from database based on user name for compare.
if (OldPassword == "123")
{
// Code for updating new password.
return "Password changed Successfully.";
}
else
{
return "User Name Or old password does not match with our Database.";
}
}
VB.Net
<WebMethod()>
Public Shared Function ResetPassword(ByVal UserName As String, ByVal OldPassword As String, ByVal NewPassword As String) As String
' Get old password from database based on user name for compare.
If OldPassword = "123" Then
' Code for updating new password.
Return "Password changed Successfully."
Else
Return "User Name Or old password does not match with our Database."
End If
End Function
Screenshot