How to call server side code asynchronously using java script in custom web part i.e. CMSAbstractWe

Srinivasa Rao Potnuru asked on June 21, 2017 17:07

Hi, How to call server side code asynchronously using java script in custom web part i.e. CMSAbstractWebPart.

There is a requirement to show documents in popup which will be opened upon clicking "view more" button in the custom web part.

Please help how can we implement this in portal template.

Thanks & Regards, Srinivas

Recent Answers


Mike Wills answered on June 21, 2017 17:27

Hi Srinivasa,

You can create a Web API on the server side. Here's how to do it in Kentico: https://docs.kentico.com/k10/developing-websites/using-asp-net-web-api-with-kentico

And then call the Web API in jQuery: http://api.jquery.com/jquery.getjson/

Mike

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on June 21, 2017 17:28

You can't call user control methods with javascript, so you'll either need to implement a service to call it or simply call Kentico REST api in order to get data.

1 votesVote for this answer Mark as a Correct answer

Development Support answered on June 21, 2017 19:35 (last edited on June 21, 2017 19:35)

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on June 21, 2017 19:35 (last edited on June 21, 2017 19:37)

Depending on what your needs are, there are also 2 items that can help.

The Webpart to API converter can allow you to run a webpart (which has access to server side code) that can return something like JSON or HTML and present it. I've done similar to your situation by creating a page with a repeater that renders the display HTML code, then use the Webpart to API converter to convert it to a feed so in javascript i can call it, get the details (passing a url parameter), and then just insert the returning content into the details display div or what not.

Also Eric's Ajax Helper can help you if you put your custom code in a Macro method.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.