Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple IF/Else not working

Status
Not open for further replies.

Jimuniguy

Technical User
Mar 6, 2002
363
GB
Hi,

Why does this not work for? It keeps asking for a then statement.

Code:
<% 
If Pageref = &quot;../Staff/Staffintro.asp&quot; 
Then  
<!-- #include file=&quot;testing.ASP&quot; -->
Else 
Response.Write &quot; &quot;
End If %>

Thank you

James
 
You would write it like this:

<%
If Pageref = &quot;../Staff/Staffintro.asp&quot; then

< !-- #include file=&quot;testing.ASP&quot; -->
Else
Response.Write &quot; &quot;
End If %>

* &quot;then&quot; has to be on the same line with the if statement
&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Actually, one addition:
Code:
<% 
If Pageref = &quot;../Staff/Staffintro.asp&quot; then

  %>< !-- #include file=&quot;testing.ASP&quot; --><%
Else 
    Response.Write &quot; &quot;
End If %>

Include statements are not ASP, so therefore they need to be outside the ASP sections of the code in order to executed.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Here's another variation for the mix:


<%
If Pageref = &quot;../Staff/Staffintro.asp&quot; then
Response.Write &quot;<!-- #include file=&quot;&quot;testing.ASP&quot;&quot; -->&quot;
Else
Response.Write &quot; &quot;
End If
%>

This way you don't have to hop in and out of asp and html. ====================================
I love people. They taste just like
chicken!

 
Same thing, th basic idea here is (as mithralhall and I both show above) that the include must be in the html portion of the code. The commenting syntax used around the include is strictly html format commenting. These includes are processed by the server and are actually the basis of shtml.

As a sidenote, the hopping is only an illusion, you never saw it ;)

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
one addition to the thread - because ASP is weakly typed I try and impose a certain amount of typing on my code one of these is when I am performing string comparisons I try and avoid the
if( a = &quot;a&quot;) then
and try and use

if( StrComp( a, &quot;a&quot;, 1 ) = 0 ) then

I know this has the extra overhead of a function call to StrComp but I know a string comparison is taking place.

I would like to know what other users do to try and impose typing on their code

Mick



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top