I have an asp.net web forms app where I'm calling a c# code behind method from javascript using PageMethods. This works fine at first, but if I navigate to a different page and then return and trigger the method, the code behind method is not called. The onSuccess method still runs, but the method in code behind is never called. I'm at a loss here, could really use some help. Thanks!
Javascript:
$(document).on("click", ".btnLinkEmployee", function () {
var id = $(this).attr("id");
var lbEmpHidden = document.getElementById('<%= lbEmpIdHidden.ClientID %>');
lbEmpHidden.value = id;
PageMethods.GetAvailableUsers(onSuccess, onError);
function onSuccess(result) {
var radWindow = $find("<%= rwLinkEmployee.ClientID %>");
radWindow.show();
var resultArr = JSON.parse(result);
var rcb = $find("<%= rcbAvailUsers.ClientID %>");
for (var i = 0; i < resultArr.length; i++) {
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(resultArr[i].UserName);
comboItem.set_value(resultArr[i].Id);
rcb.get_items().add(comboItem);
}
}
function onError(result) {
alert(result);
console.log(result);
}
});
C#
[WebMethod]
public static string GetAvailableUsers()
{
using(var context = new TTEntities())
{
var allUsers = context.AspNetUsers.ToList();
List<AspNetUser> users = new List<AspNetUser>();
foreach(AspNetUser user in allUsers)
{
var result = context.Employees.Where(b => b.UserId == user.Id).FirstOrDefault();
if(result == null)
{
users.Add(user);
}
}
var js = new JavaScriptSerializer();
var json = js.Serialize(users);
return json;
}
}