locked
how to call a server side function using javascript? RRS feed

  • Question

  • I have added a button in person.aspx in Sharepoint Designer.I want to call a event on button click.How to do it?On button click the infomation should be inserted to database..Is it possible to write a javascript function and call the method written in asp.net?if yes can u give me sample of it?
    Thursday, July 12, 2012 1:31 PM

Answers

All replies

  • If you want to do some sharepoint stuff (adding/editing items, retrieveing data, etc.) from javascript, you should consider using sharepoint javascript object model. You can get lots of samples here: http://msdn.microsoft.com/en-us/library/hh185015

    If you want to call generic server side function, you should create a web service, that would expose your function and call it. For creating sharepoint hosted WCF service, you might wanna try CKS:Dev extensions (http://cksdev.codeplex.com/), because they have a specific WCF web service project item template that will deploy your service as a feature. After it, you can use the following link to get samples how to call WCF services from javascript: http://weblogs.asp.net/ricardoperes/archive/2011/03/29/calling-wcf-web-services-from-javascript.aspx

    Thursday, July 12, 2012 1:42 PM
  • the methods to update the database is written in asp.net using visual studio.Is it possible to write a javascript function in sharepoint designer and call the .net methods using the java script function?how to do it?
    • Marked as answer by Aviw_ Saturday, August 4, 2012 3:34 PM
    • Unmarked as answer by Aviw_ Saturday, August 4, 2012 3:34 PM
    Friday, July 13, 2012 10:24 AM
  • Hello!

    It's better to create new web part (in visual studio) and deploy it to the page or create your web service and call it from JS (as Pavel mentioned above).

    You cannot call server side methods directly from JS, because JS running on client side!


    My contributions: SharePoint 2010 Solution Installer

    • Proposed as answer by Aviw_ Friday, August 3, 2012 5:05 PM
    • Marked as answer by Aviw_ Saturday, August 4, 2012 3:34 PM
    Monday, July 23, 2012 5:16 PM