会话变量经典asp

发布于 2024-11-14 11:12:42 字数 1219 浏览 2 评论 0原文

使用会话变量存储复选框的选中状态时遇到问题。我正在使用分页,因此当按下每个字母时,将出现一个复选框,并将相应的字母存储为其值。当选中复选框时,其状态将被保存,但问题是,当我取消选中该复选框时,它仍保持选中状态。也不知道这是否相关,但我已将按钮更改为看起来像超链接,因此我可以使用 post 方法而不是使用查询字符串,因为我不想使用它。下面提供的代码

<form action="Table.asp" method="post" name="form2">
<input type="submit" name="Button" value="#" style="background:transparent;border:0;display:inline;color:#00F;text-decoration:underline;padding:0px;cursor:pointer">
<% for i = 97 to 122 %>     
     <input type="submit" name="Button" value="<%=CHR(i) %>" style="background:transparent;border:0;display:inline;color:#00F;text-decoration:underline;padding:0px;cursor:pointer;">&nbsp;
<% next %>

 </br></br></br>

 <%
    alphaB = request.form("Button")
 if alphaB <>"" then

        alphaCheck = request.form("checkBox")
        if alphaCheck <>"" then
            session("checkBox_"&alphaCheck) = "checked"
        else
            session("checkBox_"&alphaCheck) = ""
        end if

        %>
        <input type="checkbox" name="checkBox" value="<%=alphaB %>" <%=session("checkBox_"&alphaB) %>>
        <%
        response.write alphaB

 end if

I have a problem when using session variables to store the checked state of a checkbox. I'm using pagination so when each letter is pressed a checkbox will appear with the respective letter stored as its value. When a checkbox is checked its state is saved, however the problem is that when i uncheck the checkbox it remains checked. Also dont know if this is relevant but I've changed the buttons to look like hyperlinks so i can use post method instead of using querystring as I'd prefer not to use it. Code provided below

<form action="Table.asp" method="post" name="form2">
<input type="submit" name="Button" value="#" style="background:transparent;border:0;display:inline;color:#00F;text-decoration:underline;padding:0px;cursor:pointer">
<% for i = 97 to 122 %>     
     <input type="submit" name="Button" value="<%=CHR(i) %>" style="background:transparent;border:0;display:inline;color:#00F;text-decoration:underline;padding:0px;cursor:pointer;"> 
<% next %>

 </br></br></br>

 <%
    alphaB = request.form("Button")
 if alphaB <>"" then

        alphaCheck = request.form("checkBox")
        if alphaCheck <>"" then
            session("checkBox_"&alphaCheck) = "checked"
        else
            session("checkBox_"&alphaCheck) = ""
        end if

        %>
        <input type="checkbox" name="checkBox" value="<%=alphaB %>" <%=session("checkBox_"&alphaB) %>>
        <%
        response.write alphaB

 end if

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福丶如此 2024-11-21 11:12:42

您应该在回发之前保存“未选中”的值,然后使用该值。

        <form action="Table.asp" method="post" name="form2">
        <input type="submit" name="Button" value="#" style="background:transparent;border:0;display:inline;color:#00F;text-decoration:underline;padding:0px;cursor:pointer">
        <% for i = 97 to 122 %>     
             <input type="submit" name="Button" value="<%=CHR(i) %>" style="background:transparent;border:0;display:inline;color:#00F;text-decoration:underline;padding:0px;cursor:pointer;"> 
        <% next %>

         </br></br></br>

         <%
            alphaB = request.form("Button")
         if alphaB <>"" then

                alphaCheck = request.form("checkBox")
                if alphaCheck <>"" then
                    session("checkBox_"&alphaCheck) = "checked"
                else
                'EDIT  use last one
                    session("checkBox_"&session("lastOne")) = ""
                end if

                'EDIT  save the last one in session
                session("lastOne") = alphaB

                %>
                <input type="checkbox" name="checkBox" value="<%=alphaB %>" <%=session("checkBox_"&alphaB) %>>
                <%
                response.write alphaB

         end if
         %>

You should save the value you 'unchecked' before you postback, and then use this value.

        <form action="Table.asp" method="post" name="form2">
        <input type="submit" name="Button" value="#" style="background:transparent;border:0;display:inline;color:#00F;text-decoration:underline;padding:0px;cursor:pointer">
        <% for i = 97 to 122 %>     
             <input type="submit" name="Button" value="<%=CHR(i) %>" style="background:transparent;border:0;display:inline;color:#00F;text-decoration:underline;padding:0px;cursor:pointer;"> 
        <% next %>

         </br></br></br>

         <%
            alphaB = request.form("Button")
         if alphaB <>"" then

                alphaCheck = request.form("checkBox")
                if alphaCheck <>"" then
                    session("checkBox_"&alphaCheck) = "checked"
                else
                'EDIT  use last one
                    session("checkBox_"&session("lastOne")) = ""
                end if

                'EDIT  save the last one in session
                session("lastOne") = alphaB

                %>
                <input type="checkbox" name="checkBox" value="<%=alphaB %>" <%=session("checkBox_"&alphaB) %>>
                <%
                response.write alphaB

         end if
         %>
默嘫て 2024-11-21 11:12:42

我要做的是使用隐藏字段来保存最后一个字母

        hidAlphaCheck = request.form("lastcheckbox")
    alphaCheck = request.form("checkBox")
    if alphaCheck <>"" then
        session("checkBox_"&hidAlphaCheck) = "checked"
    else
        session("checkBox_"&hidAlphaCheck) = ""
     end if
    ...
    <input type="checkbox" name="checkBox" value="<%=alphaB %>" <%=session("checkBox_"&alphaB) %>>   
    <input type="hidden" name="lastcheckbox" id="lastcheckbox" value="<%=alphaB%>" />  

what i would do is use a hidden field to save the last letter

        hidAlphaCheck = request.form("lastcheckbox")
    alphaCheck = request.form("checkBox")
    if alphaCheck <>"" then
        session("checkBox_"&hidAlphaCheck) = "checked"
    else
        session("checkBox_"&hidAlphaCheck) = ""
     end if
    ...
    <input type="checkbox" name="checkBox" value="<%=alphaB %>" <%=session("checkBox_"&alphaB) %>>   
    <input type="hidden" name="lastcheckbox" id="lastcheckbox" value="<%=alphaB%>" />  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文