Conditional html blocks

Discussion in 'ASP .Net' started by Richard Frenkel, Jan 10, 2005.

  1. 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).
    Richard Frenkel, Jan 10, 2005
    #1
    1. Advertising

  2. Richard Frenkel

    Raterus Guest

    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

    "Richard Frenkel" <> wrote in message news:...
    > 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).
    >
    Raterus, Jan 10, 2005
    #2
    1. Advertising

  3. Richard Frenkel

    Karl Seguin Guest

    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

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Richard Frenkel" <> wrote in message
    news:...
    > 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).
    >
    Karl Seguin, Jan 10, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. estafford

    Help writing conditional blocks

    estafford, Aug 19, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,198
    estafford
    Aug 19, 2003
  2. Arjen
    Replies:
    3
    Views:
    425
    Scott Allen
    Feb 27, 2005
  3. Robert Brewer

    Conditional except: blocks

    Robert Brewer, Jan 2, 2004, in forum: Python
    Replies:
    2
    Views:
    418
  4. matt
    Replies:
    1
    Views:
    240
    George Ogata
    Aug 6, 2004
  5. Steven Taylor
    Replies:
    9
    Views:
    235
    Brian Candler
    Apr 27, 2009
Loading...

Share This Page