Alex Rivera | Logout

Conditionally excluding a block of html in ASP.NET WebForms

Asked 2009-04-04T02:20:34.643
42

This is just a simple question: how do I exclude a piece of html on an aspx web form from being returned by the server, based on a server-side evaluation?

I'm not talking about a control specifically since they tend to have Visible parameters, but rather just some raw html.

Edit
Report

1 Answer

86

Some people object to the following method but its one that no one has answered with and I feel that it should be shown as an option. It can be handy when used properly.

<% if (ShowLabel) {%>
<label>This will not be shown if the ShowLabel property evaluates false</label>
<%}%>

To make this work you would have a public or protected property on your page called ShowLabel which returns a boolean.

answered 2009-04-04T02:49:45.183

Your Answer