您可以尝试
PageMethods,只需添加
using和
[WebMethod]
using System.Web.Services;public static class HR { [WebMethod] public static int GetEmployeeCount(string department) { int count = 0; ... return count; } }
在aspx中,像这样修改您的scriptManager
<asp:scriptManager ID="scriptManager1" runat="server" EnablePageMethods="true"></asp:scriptManager>
然后您可以通过这种方式在JS中调用方法
function myJS_method() { var departments = $get("Departments"); // your string value PageMethods.GetEmployeeCount(departments , onSucess, onError); function onSucess(result) { // your pre when it is OK // result is the return value of your C# method } function onError(result) { alert('Error' + result); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)