ASP嵌套,如果不工作

时间:2014-02-06 19:07:50

标签: asp-classic iis-7.5

以下代码段不起作用,有人可以帮我识别问题。我在IIS 7.0上使用ASP

代码:

<%If session("var") <> "" Then
    If( instr(strSQL("Platform"), session("osversion")) > 0  ) Then %>
        <input type="image" src="images/download2.gif" name="submit" value="submit" />
    <%Else %>
        <p style="font-weight:bold"> SOME ERROR MESSAGE</p>
    <%End If %>        
<%Else %>
    <input type="image" src="images/download2.gif" name="submit" value="submit" />
<%End If %>

问题是否与经典ASP的IIS 7.0配置有关?

2 个答案:

答案 0 :(得分:0)

尝试删除嵌套()中的“If”。像下面的代码:

<%If session("var") <> "" Then
    If instr(strSQL("Platform"), session("osversion")) > 0  Then %>
        <input type="image" src="images/download2.gif" name="submit" value="submit" />
    <%Else %>
        <p style="font-weight:bold"> SOME ERROR MESSAGE</p>
    <%End If %>        
<%Else %>
    <input type="image" src="images/download2.gif" name="submit" value="submit" />
<%End If %>

现在,在第一个if条件If session("var") <> "" Then中发生的事情,由于<%Else %>,应始终存在输出。该问题将被修改为nested if。检查strSQL("Platform")session("osversion")的值。如果这两个都没问题,请立即检查instr(,)。您甚至可以If instr(strSQL("Platform"), session("osversion")) > 0 Then更改为If true Then,只是为了检查它是否有效。

答案 1 :(得分:0)

  • 尽量避免&lt;%和%&gt;的混乱,这会使其无法读取。
  • 其次不要在你的不同地方重复相同的字符串 代码。
  • 第三尝试结合逻辑。
  • 第四个拉出字符串

代码......

  • 命题A:会话(“var”)&lt;&gt; “”
  • 命题B:instr(strSQL(“Platform”),session(“osversion”))&gt; 0

您的代码:

if a
    if b
        do alfa
    else
        do bravo
else
    do alfa

重写:

if not a or b
    do alfa
else
    do bravo

现在在ASP

<%
dim showButton, errMsg
showButton = "<input type='image' src='images/download2.gif' name='submit' value='submit' />"
errMsg = "<p style='font-weight:bold'> SOME ERROR MESSAGE</p>"
If session("var") <> "" Then
    If( instr(strSQL("Platform"), session("osversion")) > 0  ) Then 
        response.write showButton
    Else
        response.write errMsg
    End If
Else
    response.write showButton
End If
%>



<%
dim showButton, errMsg
showButton = "<input type='image' src='images/download2.gif' name='submit' value='submit' />"
errMsg = "<p style='font-weight:bold'> SOME ERROR MESSAGE</p>"
If session("var") = "" or  (instr(strSQL("Platform"), session("osversion")) > 0) Then 
    response.write showButton
Else
    response.write errMsg
End If
%>



<%
If session("var") = "" or (instr(strSQL("Platform"), session("osversion")) > 0) Then 
    response.write "<input type='image' src='images/download2.gif' name='submit' value='submit' />"
Else
    response.write "<p style='font-weight:bold'> SOME ERROR MESSAGE</p>"
End If
%>
相关问题