如何在ASP Classic中正确结束IF ELSE语句?

时间:2014-08-14 19:57:55

标签: vbscript asp-classic

我在搜索结果页面中添加了IF语句,以便在用户未提供通知ID或通知日期时,它不会运行长时间运行的过程。它工作正常,但在错误消息下方显示新搜索框。 End If必须在错误的地方或其他地方,但我似乎无法弄明白。

“新搜索”html应该一直显示,而不是有条件地显示,但它似乎只显示他们是否进行了有效的搜索。

<%If task = "searchNotices" Then%>

<HTML>
<HEAD>
<TITLE>Notification System</TITLE>
<%Response.Write(NoEncode(GetStyleSheet("main")))%>
<script LANGUAGE="JavaScript">
<!--
function popUpWin(thePage,theWidth,theHeight,theTop,theLeft,theName) {
        var features ="status=no,scrollbars=yes,resizable=yes,width=" + theWidth +     ",height=" + theHeight + ",top=" + theTop + ",left=" + theLeft;

        var openit = window.open(thePage, theName, features);
        return;
}
-->
</script>
</HEAD>
<BODY>

<% <!-- begin what I added:-->

dim errorNeedsIdOrDate
errorNeedsIdOrDate = "<STRONG>Error: must input either a notice date or notice id.</STRONG><BR>"

IF isNull(noticedate) and isNull(noticeid) Then 
Response.Write errorNeedsIdOrDate
Else
<!-- end what I added-->
    Set rs = Obj.GetNoticeList (reterror, CInt(gSiteID), CLng(NoticeOwnerID), 9,cint(getPrint),cint(getFax),cint(getEmail),cint(getsuspend),noticedate, noticeid, null)

    if err <> 0 then LogError true, "notice_list.asp", "Call to NoticeData.GetNoticeList failed.", Err

    If retError <> "" Then 
    LogErrorMessage EVENT_ASP_EXCEPTION, true, "notice_list.asp", "Call to NoticeData.GetNoticeList failed.", retError
    Else
    %>
    <STRONG>Notice Search Results</STRONG><BR>
    <%if not rs.EOF then%>
                                                                                                                                                                                                                                                                                                                                                                                                                                <TABLE border=0 cellspacing=0 cellpadding=2>
    <TR class="DataHeaderRow">
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1"><STRONG>Send Now?</STRONG></TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">NoticeID</TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">Notice Sent</TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">NoticeType</TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">HowToSend</TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">Status</TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">AccountNumber</TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">Send To</TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">Insured</TD>
        <TD BGCOLOR="CCCCCC" NOWRAP><font size="1">Policy(s)</TD>
        <form action="notice_resend.asp" method="get" id=form1 name=form1>
        <input type="hidden" name="task" value="passID">
        <input type="hidden" name="NoticeOwnerID" value="<%=EncodeHTML(NoticeOwnerID)%>">
    </TR>
        <%
        Do until rs.EOF
        'HowToSend,NoticeType,DueDate,CancelDate,DaysPastDue,AmountDue,LateCharge,
        'TotalDue,PolicyNumbers,AccountNumber,NoticeID,insuredname,agentname,insconame
        if (not IsNull(rs("DateSent"))) then
            if (rs("SendStatus") > 1) then
                Select Case rs("HowToSend")
                Case 1
                    sMediaKind = "print"
                Case 2
                    sMediaKind = "fax"
                Case 3
                    sMediaKind = "email"
                Case else
                    sMediaKind = ""
                End Select
            end if
        end if
        %>
    <TR>
        <TD ALIGN="CENTER">
<%              if (rs("HowToSend") = NOTICE_SEND_NOSEND) then  %>
                &nbsp;
<%              else                            %>
                <INPUT TYPE="CHECKBOX" NAME="IDList" VALUE="<%=EncodeHTML(rs("NoticeID"))%>">
<%              end if                          %>              
        </TD>
        <TD>
<%              if ((CInt(gUserAccessLevel) > CInt(ACCESS_USER)) and rs("SendStatus")=0) then   %>
                <a href="javascript:popUpWin('ModifyNotice.aspx?noticeid=<%=EncodeURL(rs("id"))%>&refresh=no',500,300,350,150,'modifynotice')">
<%              end if  %>
                <font size="1"><%=EncodeHTML(rs("id"))%>
<%              if ((CInt(gUserAccessLevel) > CInt(ACCESS_USER))  and rs("SendStatus")=0) then  %>
                </a>
<%              end if  %>
        </TD>
        <TD>
            <font size="1">
            <% If (sMediaKind <> "") Then %>
                <a href="javascript:popUpWin('ViewNoticeWindow.asp?noticeid=<%=EncodeURL(rs("NoticeID"))%>&kind=<%=EncodeURL(sMediaKind)%>',800,320,200,50,'displaynotice')">
            <% End If %>
                <%=EncodeHTML(rs("DateSent"))%>
            <% If (sMediaKind <> "") Then %>
                </a>
            <% End If %>
            </font>
        </TD>
        <TD><font size="1"><%=EncodeHTML(rs("Notice_name"))%></TD>
        <TD><font size="1">
        <%Select Case rs("HowToSend")%>
        <%Case 1%>
        Print
        <%Case 2%>
        Fax
        <%Case 3%>
        Email
        <%Case -1%>
        Suspended
        <%End Select%>
        </TD>
        <TD nowrap><font size="1">
        <%Select Case rs("SendStatus")%>
        <%Case 0%>
        Needs Sending
        <%Case 1%>
        Not Yet Confirmed
        <%Case 2%>
        Confirmed Sent
        <%Case 3%>
        Cancelled on resend
        <%End Select%>
        </TD>
        <TD><font size="1"><%=EncodeHTML(rs("AccountNumber"))%>&nbsp;</TD>
        <TD><font size="1">
        <%=NoEncode(FormatSendTo(rs))%>

        </TD>
        <TD><font size="1"><%=EncodeHTML(rs("insuredname"))%>&nbsp;</TD>
        <TD NOWRAP><font size="1"><%=EncodeHTML(rs("PolicyNumbers"))%>&nbsp;</TD>
    </TR>

        <%rs.MoveNext
        Loop
        %>
    <TR>    
    <TD COLSPAN="15"><INPUT TYPE="submit" CLASS="MainFormBtn" VALUE="Mark For Resending"></TD>
    </form>
    </TR>
    </TABLE>
    <%else%>
        No records were found.
    <%end if
End IF

%>
    <HR SIZE="1">
    <TABLE WIDTH=410 BORDER=0 CELLPADDING=1 CELLSPACING=2>
    <TR>
    <TD colspan="2">New Search</TD>
    </TR>
    <TR>
    <form action="notice_list.asp" method="post" name="searchNotice">
    <input type=hidden name="task" value="searchNotices">
    <TD BGCOLOR="CCCCCC"><STRONG>Date&nbsp;notice&nbsp;was&nbsp;last&nbsp;sent</STRONG>&nbsp;&nbsp;&nbsp;mm/dd/yyyy</TD>
    <TD><INPUT TYPE="TEXT" SIZE="10" MAXLENGTH="10" name="noticedate"></TD>
    </TR>
    <TR>
    <TD BGCOLOR="CCCCCC"><STRONG>Notice ID</STRONG></TD>
    <TD><INPUT TYPE="TEXT" SIZE="4" MAXLENGTH="10" name="noticeid"></TD>
    </TR>
    <TR>
    <TD BGCOLOR="CCCCCC"><STRONG>How they are sent</STRONG></TD>
    <TD>
        Print<INPUT TYPE="CHECKBOX" <%If getprint="1" Then%>CHECKED<%End If%>  NAME="getprint" value="1">&nbsp;&nbsp;Fax<INPUT TYPE="CHECKBOX" <%If getfax="1"  Then%>CHECKED<%End If%> name="getfax" value="1">&nbsp;&nbsp;Email<INPUT TYPE="CHECKBOX"   name="getemail" value="1" <%If getemail="1" Then%>CHECKED<%End If%>>
        Suspended<INPUT TYPE="CHECKBOX" <%If getsuspend="1" Then%>CHECKED<%End If%>   NAME="getsuspend" value="1">
    </TD>
    </TR>
    <TR>
<!--
    <TD COLSPAN="2" ALIGN=RIGHT><INPUT STYLE="HEIGHT: 27px; WIDTH: 160px"
    type="submit"  CLASS="MainFormBtn" value="Search For Notices" id="Search"     name="SearchNotices">
-->     
    <TD>&nbsp;</TD>
    <TD>
        <INPUT STYLE="HEIGHT: 27px; WIDTH: 160px" type="submit"  CLASS="MainFormBtn"     value="Search For Notices" id="Search" name="SearchNotices">
    </TD>
    </form>
    </TR>   
    </TABLE>
    <%
    End If
%>

1 个答案:

答案 0 :(得分:0)

您的问题有点不清楚,我不明白这个脚本的目的是什么。 无论如何,在上面的脚本中你错过了在第148行结束的If语句:

您有3个主要的If语句:

IF isNull(noticedate) and isNull(noticeid) Then '1st if
Response.Write errorNeedsIdOrDate
Else


    if err <> 0 then LogError true, "notice_list.asp", "Call to NoticeData.GetNoticeList failed.", Err 'an inline statement

    If retError <> "" Then '2nd if
    LogErrorMessage EVENT_ASP_EXCEPTION, true, "notice_list.asp", "Call to NoticeData.GetNoticeList failed.", retError

    Else
    %>
    <STRONG>Notice Search Results</STRONG><BR>

    <%if not rs.EOF then 'this is the 3rd if%>

你只有两个人关闭了他们:

    <%rs.MoveNext
    Loop
    %>
<TR>    
<TD COLSPAN="15"><INPUT TYPE="submit" CLASS="MainFormBtn" VALUE="Mark For Resending"></TD>
</form>
</TR>
</TABLE>
<%else%>
    No records were found.
<%end if
End IF
%>

如果您在此处添加另一个End If语句,您的脚本将会运行,但遗憾的是我不知道它是否符合预期目的。如果还有其他任何您想问的问题,请提供更多信息,说明该脚本应该获得哪些数据以及它应该做什么。