Disable a zone based on a data source on the page

Tommy De Notarpietro asked on October 5, 2017 13:26

Can I check if a data source ( or repeater using this data source ) is empty and use this as a condition macro in the visible property?

It can be done with editable text web part by checking if cmscontext.currentdocument.idofwebpart is empty ( see: https://www.mmtdigital.co.uk/thinking/march-2014/quick-kentico-tip-hide-a-webpart-if-empty ), but it seems I can't check if a data source or repeater is empty.

Or does anyone know a good solution for this?

Recent Answers


Trevor Fayas answered on October 5, 2017 15:46

This is a tricky one. I know of a couple options to try:

  1. You can try to clone and modify the repeater web part, and in your custom version add a On Pre_Init (or OnInit, anything that will run before the webpart zone) that checks for the datasource, if it's empty sets a Macro in the macro context that you can then leverage for making the zone visible.
  2. You can try to just add a <script runat="server"></script> in your ascx transformation, perform the OnPre_init on that and set a macro that (so if the dataset is empty, that macro won't exist and you can toggle the zone based on that).
  3. Otherwise if your Repeater is hooked up to a datasource, you can create a custom control to check that data source and set a macro as well.
  4. Lastly, if your repeater logic is something predictable, you could create a macro method that simply manually performs the same data call and returns a true or false if it's empty or not, and just call that method and not even try to 'touch' the repeater.

4 may be the easiest if it's predictable, otherwise i would try 2, then 1, then 3

0 votesVote for this answer Mark as a Correct answer

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