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?

2
  • 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. Commented Feb 13, 2013 at 12:03
  • @poiuytrez:Thanks for pointing me to the right direction Commented Feb 13, 2013 at 12:06

2 Answers 2

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]
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.