Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Inludes in if-elsesif-endif

[b][red]This message was edited by pompougnac at 2004-12-19 17:0:24[/red][/b][hr]
I want to include the file "include.asp" when the value in the textbox=1. Why doesn't this work:

<%
If Request.Form("textbox") = "1" Then


'ALSO TRIED: Response.Write "" but that doesn't work either...

Else
Response.Write ""
End If
%>

Any ideas?


Comments

  • ManningManning Posts: 1,621Member
    : I want to include the file "include.asp" when the value in the textbox=1. Why doesn't this work:
    :
    : <%
    : If Request.Form("textbox") = "1" Then
    :
    : Else
    : Response.Write ""
    : End If
    : %>

    Includes happen before any ASP code is executed, which means include.asp will always be included. That doesn't mean it's code will always be executed, the IF will still take care of that.

    Your problem might have to do with extra <% and %> tags. For example, if your include.asp looked like this:

    [code]
    <%
    Response.Write "This is include.asp"
    %>
    [/code]

    Then your above code, after the include is processed, would look like:

    [code]
    <%
    If Request.Form("textbox") = "1" Then
    <%
    Response.Write "This is include.asp"
    %>
    Else
    Response.Write ""
    End If
    %>
    [/code]

    As you can see, there are nested <% tags. Your solution is to either remove the main <% and %> tags from include.asp, or move the statement outside of the <% and %> tags. IE:

    [code]
    <% If Request.Form("textbox") = "1" Then %>

    <% Else
    Response.Write ""
    End If %>
    [/code]

    That's the better of the two options, IMO
Sign In or Register to comment.