Search code examples
c#javascriptmethodscallusing

how to call C#(aspx.cs) function by using java script/Jquery by passing parameters


.aspx
 -----------------------

    <head>
     <script type="text/javascript">
    >>      $(document).ready(function () {
                $(".cssBtns").click(function () {
                    // call aspx.cs method generateInfo(this.id,this.className)
                });
            });
        </script>
    </head>
    <body>

    </body>

.aspx.cs
-----------------------

    public void generateInfo(int btnId, string className){

         print:// css button id:---
                  css button class:----
    }

how can i call generateInfo method which is aspx.cs page by using java script/JQuery. and which is the best way.


Solution

  • You can use $.ajax(), $.post(), $.get() or $.getJSON() for doing this.

    $(".cssBtns").click(function () {
         $.ajax({
            url : 'aspx function path here'
         });
    });
    

    See the link below for more reference.

    how to call an ASP.NET c# method using javascript

    http://api.jquery.com/jQuery.ajax/