0

The scenario I'm trying to build in Kentico is having a user action in one web part cause the reload/update of a second web part without reloading the whole page.

An example would be adding an item to a shopping cart: if a user clicks on the 'add item to cart' button (first webpart), then the item total in the cart (second webpart) in the page header should update without reloading the whole page.

I know how to do this with an ASP.NET MVC application, but I haven't yet figured out how to do this with Kentico.

1 Answer 1

5

This is not possible out of the box. You have two options:

  1. Create copy of a web part and adjust it according to your needs. This is a cleaner solution but can be avoided.
  2. Turn on "Use update panel" for desired web parts and do the refreshing programmatically via JavaScript. I wouldn't fear it if it's just for small portions of the website (like updating text of item total).

I'd wrap the "item total" (I guess you use the Shopping Cart Preview) web part in a div (using a container or content before/after properties) and give it a class (e.g. .cartInfo). And then query it and refresh the underlying UpdatePanel (div) by calling ASP.NET's __doPostBack().

__doPostBack(document.querySelector(".cartInfo div").id,'');

You can then hook this piece of code to any event on the page using addEventListener / attachEvent. In your case it would be click event of the "Add to cart" button. My examples are vanilla JS but you can of course use jQuery to do all that.

1
  • Thanks for the suggestion, I'll give this a try.
    – marcel_g
    Oct 27, 2015 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.