1

I am Calling an ASP.NET C# Method (Web Method) Using JavaScript.

C#:

[WebMethod]
public static List<Employee> GetEmployeeList(int DeptID,out int TotalRecordsCount)
{
    <Employee> obj = new List<Employee>();
    //obj = Geting reocrds from Database
    TotalRecordsCount = obj.Count();
    return obj;
}

Javascript:

function BindList(){
        var DeptID = 10;
        var TotalRecordsCount = 0;
        PageMethods.GetEmployeeList(DeptID,TotalRecordsCount,onsuccess);
}

Now I am getting errors, while calling above js method. Please suggest me where I done mistake.

My main aim is that, Instead of returning single list, Can I add 2 or more different lists ?

Thanks in adv.

Jagadeesh
  • 1,630
  • 8
  • 24
  • 35

1 Answers1

2

Out methods should contain the out key word when it is called like

PageMethods.GetEmployeeList(DeptID,out TotalRecordsCount, onsuccess);

But out is not a keyword in js. So I don't know if it is possible (I would be surprised). Why not return the out parameter as part of the result. So instead of just a list, a list with another value. Another thing that is unusual in your code is that you are trying to set the out parameter before calling the method.

I have never tried using an out when calling the method in Js and its probably not very good design even if it is allowed.

Also see

Is it unusual for a web service call to have an "out" parameter?

Community
  • 1
  • 1
Murdock
  • 4,352
  • 3
  • 34
  • 63
  • The OP is returning the count of list being returned. That could be taken in javascript through length property – Adil Mar 26 '14 at 09:36
  • yes, your right Adil. But - not only the count but also i want to return one more result set. Is that possible? I mean, OnSuccess(objResult1,objResult2){ } is this possible ? – Jagadeesh Mar 26 '14 at 09:43
  • Murdock, if we have only one value like count, then we can simple to add to our returning list. But for example, if i want to return one more List obj then ? (2 or more list objects) Instead of returning single list, I want to return multiple list. Is this possible ? – Jagadeesh Mar 26 '14 at 09:51
  • OK. So, finally you are telling that there is no possible way to call WebMethod() which is having out parameter. Am I right ? – Jagadeesh Mar 26 '14 at 09:52
  • @Chinni Just create a Result class that has 2 list and a Count as properties. Then rather return the result class. – Murdock Mar 26 '14 at 09:57