Tip : displaying default text for empty controls

January 04, 2008 Digital Experience
One of our users has asked how to display a default text for empty control when editing page in Sitefinity. The scenario is following: you have created a custom control, user drags it onto the page and because no properties have been set, user only sees blank space. What we want to do is display some user friendly message, something like on the screenshot below.



It is quite simple to achieve this. All you have to do is implement IEmptyControl interface in your control. The IEmptyControl interface defines a boolean property „IsEmpty“ in which you create the logic that will define the control as empty or not. In addition to that, interface defines a string function which simply returns the text you want to display if control is empty. And that's it. Take a look at the code below which illustrates this.



I have prepared a sample control which demonstrates this, so you can go ahead and download it from here, though the implementation is really trivial.

A point to note here is that you could also use IsEmpty property together with Control.DesignMode property in your CreateChildControls method to create a more complex display for empty controls (not just text).

Hope this helps.

The Progress Team