Call ASP.NET function from JavaScript?

后端 未结 20 2184
暗喜
暗喜 2020-11-22 07:21

I\'m writing a web page in ASP.NET. I have some JavaScript code, and I have a submit button with a click event.

Is it possible to call a method I created in ASP with

20条回答
  •  孤独总比滥情好
    2020-11-22 08:16

    I think blog post How to fetch & show SQL Server database data in ASP.NET page using Ajax (jQuery) will help you.

    JavaScript Code

    
    

    ASP.NET Server Side Function

    [WebMethod]
    [ScriptMethod(ResponseFormat= ResponseFormat.Json)]
    public static List GetCompanies()
    {
        System.Threading.Thread.Sleep(5000);
        List allCompany = new List();
        using (MyDatabaseEntities dc = new MyDatabaseEntities())
        {
            allCompany = dc.TopCompanies.ToList();
        }
        return allCompany;
    }
    

提交回复
热议问题