Leading In and Out of ASP

Discussion in 'C#' started by fireflyproject, Dec 17, 2007.

  1. #1
    Is it possible to move in and out of ASP in an If statement like in PHP?

    For instance in PHP you can do this:

    
    <?
       if($n = $x) {
    ?>
    <p>Content content content</p>
    <?
       }
    ?>
    
    PHP:
    Is this possible in ASP? I am getting an error when I do it this way in ASP.

    If not, what is a suitable way to print out HTML if a certain condition is met?

    Thanks!
     
    fireflyproject, Dec 17, 2007 IP
  2. alexk13

    alexk13 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    yes you can do this

    your code would look like this:
    <% 
    If (n = x) Then
    %>
       <p>Content content content</p>
    <%
    End If
    %>
    
    Code (markup):
     
    alexk13, Dec 17, 2007 IP
  3. fireflyproject

    fireflyproject Active Member

    Messages:
    969
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    70
    #3
    Hey Alex,

    When I do this, I get an error page, and it states that it was expecting the "End" even when it is there, just like you have.
     
    fireflyproject, Dec 18, 2007 IP
  4. alexk13

    alexk13 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can you post your code, so I can take a look and see if i can see a problem.
     
    alexk13, Dec 18, 2007 IP
  5. fireflyproject

    fireflyproject Active Member

    Messages:
    969
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    70
    #5
    Here is what I ended up doing. (The <!--#embed --> tags pull content into the template) I was trying to avoid having any HTML inside of the ASP by using what we are talking about.

    <%
    		dim question_1
    		dim question_2
    		question_1=Request.Form("question_1")
    		question_2=Request.Form("question_2")
    		
    		If question_1="" Then
    		Response.Write("<form method='post' action='?page=<!--#embed page[0] -->_<!--#embed page[1] -->_<!--#embed page[2] -->' name='activity'>")
    		Response.Write("<p class='bold'><!--#embed args=form,page[0]/page[1].html,page[2]_weigh_direction,weigh_direction --></p>")
    		Response.Write("<p><!--#embed args=form,page[0]/page[1].html,page[2]_weigh_questions,question_1 --><br />")
    		Response.Write("<textarea name='question_1' cols='50' rows='6'></textarea></p>")
    		Response.Write("<p><!--#embed args=form,page[0]/page[1].html,page[2]_weigh_questions,question_2 --><br />")
    		Response.Write("<textarea name='question_2' cols='50' rows='6'></textarea></p>")
    		Response.Write("<p><input type='submit' value='Submit' /></p>")
    		Response.Write("</form>")
    		Else
    		Response.Write("<p><!--#embed args=form,page[0]/page[1].html,page[2]_weigh_questions,question_1 --></p>")
    		Response.Write("You said, """ & question_1 & """<br />")
    		Response.Write("<p><!--#embed args=form,page[0]/page[1].html,page[2]_weigh_answers,answer_1 --></p>")
    		Response.Write("<p><!--#embed args=form,page[0]/page[1].html,page[2]_weigh_questions,question_2 --></p>")
    		Response.Write("You said, """ & question_2 & """<br />")
    		Response.Write("<p><!--#embed args=form,page[0]/page[1].html,page[2]_weigh_answers,answer_2 --></p>")
    		End If
    	%>
    PHP:
     
    fireflyproject, Dec 19, 2007 IP
  6. alexk13

    alexk13 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I've never seen it done like that before.

    Does that actually work - I'd be really interested to know.
     
    alexk13, Dec 19, 2007 IP
  7. fireflyproject

    fireflyproject Active Member

    Messages:
    969
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    70
    #7
    Well it's being run through an assembler script, so yeah it does work. Although I'm not too sure exactly how it works, I wasn't the one who wrote the assembler.
     
    fireflyproject, Dec 19, 2007 IP