Conditional html blocks

R

Richard Frenkel

In scripting languages such as PHP and ColdFusion, it is easy to
conditionally include a block of html using something like
(pseudocode):

<if x=true>
This is some <b>random html<b>
that gets displayed if x is true and not otherwise
</if>

I've been coding using c# and asp.net and find it impossible to do the
same thing on asp.net pages. I don't need the html block parsed, so 2
passes aren't needed (although that would be nice).
 
R

Raterus

If you are having trouble doing this with asp.net, then I don't believe you full understand how asp.net controls work. For instance, to accomplish your example you could do the following.

Put all the random html you want inside an <asp:placeholder> control

Then from a script block, you can do this

myPlaceHolder.Visible = x;

(if x is true, so will the contents of the placeholder)

--Michael
 
K

Karl Seguin

You can simply place the text in a literal or placeholder and switch the
visibility of it, pseudocode:

<asp:plaholder id="plc" runat="server">
this is some <b>random html</b>
that gets displayed if x is true and not otherwise
</asp:plaholder >

Sub Page_Load
plc.Visible = (x = true)
end sub

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top