Conditional placeholders

Optional content

Very often we want to display properties of an object, but the object is not always provided. An example can be showing address information such as street, city, etc but the address is an optional property (sometimes it is null).
OptionalContentPlaceHolder is a very handy control. It will only data bind its children if DataItem property != null. Otherwise it will not bind nor render its children.

<ow:OptionalContentPlaceholder runat="server" DataItem="<%# Model.Address %>">
	<span>Street: <%# Model.Address.Street %></span>
	<span>City: <%# Model.Address.City %></span>
	<span>PostalCode: <%# Model.Address.PostalCode %></span>
</ow:OptionalContentPlaceholder>

Optional content with fallback

<ow:OptionalContentWithFallbackPlaceholder runat="server" DataItem="<%# Model.Address %>">
	<Content>
	    <span>Street: <%# Model.Address.Street %></span>
             ...
	</Content>
        <FallbackContent>
		<span>No address has been provided.</span>
	</FallbackContent>
</ow:OptionalContentWithFallbackPlaceholder>

Conditional content

ConditionalContentPlaceHolder can be used in scenarios where two types of content should be displayed depending on Boolean condition. It acts in similar way to MultiView but does not require direct operations on indexes of active view.

<div>
    <ow:ConditionalPlaceHolder runat="server" Condition="<%#true %>">
        <ThenContent>
            This should be rendered
        </ThenContent>
        <ElseContent>
            This should NOT be rendered
        </ElseContent>
    </ow:ConditionalPlaceHolder>
</div>

<div>
    <ow:ConditionalPlaceHolder runat="server" Condition="<%#false %>">
        <ThenContent>
            This should NOT be rendered
        </ThenContent>
        <ElseContent>
            This should be rendered
        </ElseContent>
    </ow:ConditionalPlaceHolder>
</div>

Last edited Jul 12, 2011 at 1:53 PM by mgrzyb, version 7

Comments

No comments yet.