尝试解决围绕两个按钮的ASP经典脚本。它只包含两个按钮,只需要一个按钮

时间:2014-09-09 21:49:30

标签: html asp.net asp-classic

这里是ASP脚本和body标签内部的html元素。出于某种原因,它给了我两个按钮而不是一个。我的目标只是尝试删除其中一个按钮,以便它可以引导我进入查看购物车功能页面。感谢您的帮助!

<%
catid = Request.QueryString("id")
sub productInfo(connObj,category)
sqlCustomer = "SELECT * FROM qryProdsCategory WHERE ccategory = '" & Cint(category) & "'"
Set rs = Server.CreateObject ("adodb.Recordset")
rs.Open sqlCustomer, dbc, adOpenDynamic, adLockOptimistic, adCmdText
if not rs.EOF then
    if Session("sort")="0" then
        rs.sort = "cname ASC"
    end if

Response.Write "<form action="&q&Application("secureurl")&"/cart/view-cart.asp"&q&"       method="&q&"POST"&q&" name=form"&i&">"

        while not rs.EOF

            If rs("stock")="1" then

                Response.Write "<a href=""product.asp?id=" & rs("catalogID") & ""

                Response.Write "" & rs("catalogID") & "" & rs("manModNum") & "</font></td><td width=""18%"" rowspan=""2"">"
                Response.Write "<input type="&q&"hidden"&q&" name="&q&"fproductid"&q&" value="&q &  rs("catalogID")& q&">" 
                Response.Write "<input type="&q&"hidden"&q&" name="&q&"fquantity"&q&" value=1>" 
                Response.Write "<input type="&q&"hidden"&q&" name="&q&"fcat"&q&" value=" & rs("ccategory") & ">"

            End If

        rs.MoveNext
        wend

        If rs.RecordCount > 0 then
             Response.Write "<button class=""btn"" TYPE=""btn"" style=""background-color: #cb0000;color: #fff;"">ADD TO CART</button> </form>" 
        End If
 Response.Write "</form>" 
else
    Response.Write "&nbsp;<P><Center><font size=""2""><h3>Sorry, but products information for the category you have chosen is not available at this moment. Please check back soon!</H3></font></center>"
    catname = "Error"
end if
end sub
%>

以下是body标签内的代码

<div class="span3">
<img src="img/team/profile1.jpg">
<div class="productSelection">
<div class="ProductTitle">
<strong style="font-size:16px;">TITLE</strong>
</div>
<h6>TITLE</h6>
<h6>TITLE</h6>


<%
call openConn()
call productInfo(dbc,catid)
%>

   

这是ASP代码的View Cart部分的编辑部分

<%
catid = Request.QueryString("id")
sub productInfo(connObj,category)
sqlCustomer = "SELECT * FROM qryProdsCategory WHERE ccategory = '" & Cint(category) & "'"
Set rs = Server.CreateObject ("adodb.Recordset")
rs.Open sqlCustomer, dbc, adOpenDynamic, adLockOptimistic, adCmdText
if not rs.EOF then
    if Session("sort")="0" then
        rs.sort = "cname ASC"
    end if

Response.Write "<form action="&q&Application("secureurl")&"/cart/view-cart.asp"&q&"      method="&q&"POST"&q&" name=form"&i&">"

        while not rs.EOF

            If rs("stock")="1" then

                Response.Write "<a href=""product.asp?id=" & rs("catalogID") & ""

                Response.Write "" & rs("catalogID") & "" & rs("manModNum") & "</font></td><td width=""18%"" rowspan=""2"">"
                Response.Write "<input type="&q&"hidden"&q&" name="&q&"fproductid"&q&" value="&q &   rs("catalogID")& q&">" 
                Response.Write "<input type="&q&"hidden"&q&" name="&q&"fquantity"&q&" value=1>" 
                Response.Write "<input type="&q&"hidden"&q&" name="&q&"fcat"&q&" value=" &  rs("ccategory") & ">"

            End If

        rs.MoveNext
        wend
   %>

1 个答案:

答案 0 :(得分:1)

您正在获取两个按钮,因为您是在While循环中创建它们的。 while循环中的条件可能会满足几次(我的意思是你的代码会一直转到你创建按钮的Else部分)。将按钮创建逻辑移出while循环。而且,你创建按钮的If ... Else代码没有意义。即无论条件创建按钮。根据我的理解,只有在有记录的情况下,您才会尝试显示“添加到购物车”按钮。如果这是真的,我建议这样的事情。

<%
catid = Request.QueryString("id")
sub productInfo(connObj,category)
    sqlCustomer = "SELECT * FROM qryProdsCategory WHERE ccategory = '" & Cint(category) & "'"
    Set rs = Server.CreateObject ("adodb.Recordset")
    rs.Open sqlCustomer, dbc, adOpenDynamic, adLockOptimistic, adCmdText
    if not rs.EOF then
        if Session("sort")="0" then
            rs.sort = "cname ASC"
        end if

Response.Write "<form action="&q&Application("secureurl")&"/cart/view-cart.asp"&q&"      method="&q&"POST"&q&" name=form"&i&">"

            while not rs.EOF

                If rs("stock")="1" then

                    Response.Write "<a href=""product.asp?id=" & rs("catalogID") & ""

                    Response.Write "" & rs("catalogID") & "" & rs("manModNum") & "</font></td><td width=""18%"" rowspan=""2"">"
                    Response.Write "<input type="&q&"hidden"&q&" name="&q&"fproductid"&q&" value="&q &  rs("catalogID")& q&">" 
                    Response.Write "<input type="&q&"hidden"&q&" name="&q&"fquantity"&q&" value=1>" 
                    Response.Write "<input type="&q&"hidden"&q&" name="&q&"fcat"&q&" value=" & rs("ccategory") & ">"

                End If

            rs.MoveNext
            wend

            If rs.RecordCount > 0 then
                Response.Write "<button class=""btn"">ADD TO CART</button>" 
            End If
 Response.Write "</form>" 
    else
        Response.Write "&nbsp;<P><Center><font size=""2""><h3>Sorry, but products information for the category you have chosen is not available at this moment. Please check back soon!</H3></font></center>"
        catname = "Error"
    end if
end sub
%>

希望这有帮助!如果有,请投票并接受答案。一切顺利: - )