How to call web method in asp.net application

Mohammad Qasim 576 Reputation points
2021-02-05T18:42:33.097+00:00

Greetings,

have designed asp.net application ,
Requirement : I have designed web method name "test()" on default.aspx page , want to call on using ajax.

Solution required : how can I call this method from client side using ajax ,jquery call.

Just let me know , where to design web method to be called using Client Side to return json

Images attached for reference:

64689-webmethod.png

Thanks

ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
315 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yihui Sun-MSFT 801 Reputation points
    2021-02-08T06:21:31.693+00:00

    Hi @Mohammad Qasim ,
    According to your needs, I wrote an example, you can refer to it.
    Default.aspx

        public partial class _Default : Page  
        {  
            protected void Page_Load(object sender, EventArgs e)  
            {  
            }  
            [WebMethod]  
            public static string test(string querytype)  
            {  
                return "{test:\'test\'}";  
            }  
        }  
    

    Default.aspx.cs

    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">  
        <div>  
            <asp:Button ID="Button1"  
                Text="Test"  
                OnClientClick="BindTreeview()"  
                runat="server" />  
        </div>  
    </asp:Content>  
    

    JS on Default.aspx.cs
    65167-test2.png
    Result
    65241-test.gif


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Best Regards,
    YihuiSun

    1 person found this answer helpful.
    0 comments No comments