0

Is it possible to call a C# function which is inside a specific class file by javascript?

My Function is like this

    public static void PrintPDF()
    {
    }

and this function is inside a class file XSLTHelper In C# I can call this function by XSLTHelper.PrintPDF();. Is there is any way to do the same from javascript?

None
  • 5,582
  • 21
  • 85
  • 170
  • 2
    Do you mean that you would like to call a server side function (C#) from a client side function (javascript)? If yes, you should learn what is a webservice. – poiuytrez Feb 13 '13 at 12:03
  • @poiuytrez:Thanks for pointing me to the right direction – None Feb 13 '13 at 12:06

2 Answers2

1

You can use jquery and Ajax to call an action Method which can call the PrintPDF function?

CR41G14
  • 5,464
  • 5
  • 43
  • 64
1

You can use Ajax call as below:

     $.ajax({
      type: "POST",
      url: "PageName.aspx/PrintPDF",
      contentType: "application/json; charset=utf-8",
      dataType: "json",

      success: function (msg) {
           if (msg.d == 'Success') {

            }

        }

   });

Your function needs to have attribute as follow:

[System.Web.Services.WebMethod]
Zaki
  • 5,540
  • 7
  • 54
  • 91