How To Reload Ng-repeat When I Clicked Button Asp.net (angularjs)
How would you pass data code to angularjs variable. its working fine when the page loads. But when I click the button, for filter data. The server side does not load data. $scope.
Solution 1:
Finally I Solve my Problem :)
$scope.myData.doClick = function () {
$http.post('abc.aspx/GetEmployees', { response: {} })
.then(functionsuccessCallback(response) {
$scope.studentinformation = {};
$scope.studentattendance = JSON.parse(response.data.d);
})
.error(function (response, status, headers, config) {
$scope.status = status;
});
}
//HTML
<divng-click="myData.doClick()">Click here</div>
//c#
[WebMethod]
publicstaticstringGetEmployees()
{
string Query "Select * from tblstudent WHERE student_name = 'Adeel'";
var getstudentattendance = DbAccess.GetResult(Query);
studentattendancejson = JsonConvert.SerializeObject(getstudentattendance, Formatting.Indented);
return studentattendancejson;
}
Ajax call with parameter
$scope.myData.doClick = function (item,event) {
var startdate = document.getElementById('txtstart').value;
var enddate = document.getElementById('txtend').value;
$.ajax({
type: "POST",
url: "studentattendance.aspx/GetEmployees",
data: JSON.stringify({ title: startdate, songname: enddate}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$scope.studentattendance = {};
$scope.studentattendance = JSON.parse(msg.d);
$scope.$apply();
},
error: function (msg) {
alert(msg.d);
}
});
}
ASP.NET C#//
publicstaticstringGetEmployees(string title, string songname)
{
}
Solution 2:
Page_Load
is run as one of the last events in the page life cycle every time the page posts back. So, when you click the button the page posts back and the btnSearch_Click1
event fires and then the Page_load
event runs. You need to modify your Page_Load
event as follows, so it doesn't overwrite studentattendancejson
:
protectedvoidPage_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {
string Query = "SELECT ts.Idx, ts.student_name,ts.father_name,t.attendancedate,t2.class_name,tat.attendanceType FROM tblstudentattendence t " +
"INNER JOIN tblStudent ts ON ts.student_id = t.student_id INNER JOIN tblclassinfo t2 ON t.class_id = t2.idx " +
"INNER JOIN tblAttendanceType tat ON t.attendancetype_Id = tat.Idx";
var getstudentattendance = DbAccess.GetResult(Query);
studentattendancejson = JsonConvert.SerializeObject(getstudentattendance, Formatting.Indented);
}
}
Hope this helps. Let me know if you need anything else.
Post a Comment for "How To Reload Ng-repeat When I Clicked Button Asp.net (angularjs)"