Steve Freeman
Steve Freeman

Reputation: 15

simple if then else for .asp page

All I need is to compare a given number vs a fixed number, and if it true, return one paragraph and if not true, return an alternative paragraph. I have no ASP experience, and minimal html skill.

I have a changing dollar figure in a database field called [now list]; and this field has been formatted as currency.

I want the page to evaluate whether or not [now list] is > or < 5 (or 10, or 20 or any numeral); but for now let's just evaluate against the number 5.

I turn my webpage into html code that I can edit. I tried this:

IF [now list]<5, 
    then "write this big paragraph which may or may not include lots of html links" 
    else "write different paragraph I can make up to suit me."     
ENDIF

If [now list] < 5, THEN write big, ELSE write different. 

I have the idea that this code will go on the page in the place where I want the paragraph to show up, regardless of which paragraph gets picked? Right? When I tested the page, it shows the IF statement written out, not the result of the analysis I'd hoped for.

Please help me. For my benefit, please pretend I am a bright 7-yr old kid; even though I am 57. Thanks in advance.

Upvotes: 0

Views: 1117

Answers (1)

Obsidian Age
Obsidian Age

Reputation: 42384

You need to make sure to wrap your code in the standard ASP.NET markup, <% and %> tags. These tags tell the page to render what it's about to read as ASP.NET rather than HTML (the default). The tags will get invisibly stripped from the output, and only the contents of the ASP.NET code will execute.

In addition to this, while you would typically think to only run your code within a set of these tags, you can actually 'break out' of the code logic while still inside an ASP.NET conditional:

<% if(now_list < 5) { %>

<a href="link1.html">Link 1</a>
<a href="link2.html">Link 2</a>
<a href="link3.html">Link 3</a>

<% } else { %>

<p>Different HTML code</p>

<% } %>

In the above example, a number of links will output when now_list is less than 5, and Different HTML code will output when it is equal to or greater than 5.

Hope this helps! :)

Upvotes: 0

Related Questions