在我这种情况下,如何使用asp.net中的Cache

liu_dashi 2013-04-11 02:01:10
我在做一个问卷调查功能,在页面B中有一个Repeater控件,其中嵌套有RadioButtonList控件。在选项中我随意选几个。这时候我会跳转到页面A中,然后再回到页面B。我想要之前选择的几个选项仍然是选定状态。想到要用Cache来做,我没使用过Cache,不知到在这种业务中如何实现?
...全文
163 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu_dashi 2013-04-11
  • 打赏
  • 举报
回复
great!
md5e 2013-04-11
  • 打赏
  • 举报
回复
引用 9 楼 liu_dashi 的回复:
引用 8 楼 liuchaolin 的回复: 这种方式是可以,不过你没明白我的意思。比方你开始只选了1.1、2.2、3.3这三道题,然后要回到上一页面做些操作,最后返回该页时。session中保存的只有“1.1、2.2、3.3”。这时候如何给对应的radiobuttonlist初始化选定值呢?这时候arycheck[i] 和 jQuery(item).find 对不上了吧就
在点下一步前就对映好,不选也要留空 function getCheckID(){ var checklist=""; jQuery(".table1 > tbody > tr").each(function (i, item) { if (jQuery(item).find("input[type='radio']:checked").length <= 0){ checklist+="," } else{ checklist+=jQuery(item).find("input[type='radio']:checked").eq(0).val() + "," } }); jQuery("#hd").val(checklist.substring(0,checklist.length-1)) }
liu_dashi 2013-04-11
  • 打赏
  • 举报
回复
引用 8 楼 liuchaolin 的回复:
这种方式是可以,不过你没明白我的意思。比方你开始只选了1.1、2.2、3.3这三道题,然后要回到上一页面做些操作,最后返回该页时。session中保存的只有“1.1、2.2、3.3”。这时候如何给对应的radiobuttonlist初始化选定值呢?这时候arycheck[i] 和 jQuery(item).find 对不上了吧就
md5e 2013-04-11
  • 打赏
  • 举报
回复
md5e 2013-04-11
  • 打赏
  • 举报
回复

<%@ Page EnableEventValidation="false" ValidateRequest="false"  Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
    .label
    {
        text-align:center; width:600px;
    }
    .red
    {
        color:#ff0000;
    }
    </style>
     <script src="/js/jquery.js" charset="utf-8"></script>
     <script>
         jQuery(document).ready(function () {
             var checklist = "1,1,2,3,4,1,5,1";
             var arycheck = checklist.split(",");
             jQuery(".table1 > tbody > tr").each(function (i, item) {
                 jQuery(item).find("input[type='radio'][value='" + arycheck[i] + "']").attr("checked", true);
                 //jQuery(item).find("input[type='radio']").eq(parseInt(arycheck[i]) - 1).attr("checked", true);

             })
         });
         function checkForm() {
             var _message = "";
             var _obj;
             jQuery(".red").removeClass("red")
             jQuery(".table1 > tbody > tr").each(function (i, item) {
                 if (jQuery(item).find("input[type='radio']:checked").length <= 0) {
                     _obj = jQuery(item).find("input[type='radio']").eq(0);
                     _message += jQuery(item).find(".td1").eq(0).text() + "没有勾选 ";
                     jQuery(item).addClass("red");
                     //return false;
                 }
             });
             if (_message != "") {
                 alert(_message);
                 jQuery(_obj).focus();
                 return false;
             }
             return true;
         }
     </script>
</head>
<body>
    <form id="form1" runat="server">
    <table class="table1">
    <tbody>
        <tr>
            <td class="td1">
                <span style="color: #FF001E">*</span> 1.1
            </td>
            <td class="td2">
                <span>标题1</span>
            </td>
            <td class="td3">
                <asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="Horizontal" runat="server"
                    CssClass="radio">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>
            <td class="td1">
                <span style="color: #FF001E">*</span> 1.2
            </td>
            <td class="td2">
                <span>标题1</span>
            </td>
            <td class="td3">
                <asp:RadioButtonList ID="RadioButtonList4" RepeatDirection="Horizontal" runat="server"
                    CssClass="radio">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>
            <td class="td1">
                <span style="color: #FF001E">*</span> 1.3
            </td>
            <td class="td2">
                <span>标题1</span>
            </td>
            <td class="td3">
                <asp:RadioButtonList ID="RadioButtonList5" RepeatDirection="Horizontal" runat="server"
                    CssClass="radio">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        </tbody>
    </table>
    <table class="table1">
    <tbody>
        <tr>
            <td class="td1">
                <span style="color: #FF001E">*</span> 2.1
            </td>
            <td class="td2">
                <span>标题1</span>
            </td>
            <td class="td3">
                <asp:RadioButtonList ID="RadioButtonList2" RepeatDirection="Horizontal" runat="server"
                    CssClass="radio">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>
            <td class="td1">
                <span style="color: #FF001E">*</span> 2.2
            </td>
            <td class="td2">
                <span>标题1</span>
            </td>
            <td class="td3">
                <asp:RadioButtonList ID="RadioButtonList6" RepeatDirection="Horizontal" runat="server"
                    CssClass="radio">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        </tbody>
    </table>
    <table class="table1">
    <tbody>
        <tr>
            <td class="td1">
                <span style="color: #FF001E">*</span> 3.1
            </td>
            <td class="td2">
                <span>标题1</span>
            </td>
            <td class="td3">
                <asp:RadioButtonList ID="RadioButtonList3" RepeatDirection="Horizontal" runat="server"
                    CssClass="radio">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>
            <td class="td1">
                <span style="color: #FF001E">*</span> 3.2
            </td>
            <td class="td2">
                <span>标题1</span>
            </td>
            <td class="td3">
                <asp:RadioButtonList ID="RadioButtonList7" RepeatDirection="Horizontal" runat="server"
                    CssClass="radio">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>
            <td class="td1">
                <span style="color: #FF001E">*</span> 3.3
            </td>
            <td class="td2">
                <span>标题1</span>
            </td>
            <td class="td3">
                <asp:RadioButtonList ID="RadioButtonList8" RepeatDirection="Horizontal" runat="server"
                    CssClass="radio">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        </tbody>
    </table>
    <asp:GridView ID="GridView1" runat="server" EnableModelValidation="True">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" CancelImageUrl="images/answer_bg.gif" DeleteImageUrl="images/banner1.jpg" />
        </Columns>
    </asp:GridView>
    <asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="False" />
    </form>

</body>
</html>
liu_dashi 2013-04-11
  • 打赏
  • 举报
回复
引用 5 楼 liuchaolin 的回复:
1\可以用层来显示隐藏来表现,这样就不存在cookie或session 2\用Session记录选项,字符格式如下"1,1,3,5", 然后可以用JS设置默认值 var checklist="<%= Session["checklist"]==""?"":Session["checklist"].ToString() %>" var arycheck=checklist.split……
又是你啊 呵呵!这个功能做的我头疼 tmd!用你这种方式的话,比如我有5个radiobuttonlist,我开始只选其中的两个,这时候arycheck[i] 和 jQuery(item).find 对不上了吧就
md5e 2013-04-11
  • 打赏
  • 举报
回复
1\可以用层来显示隐藏来表现,这样就不存在cookie或session 2\用Session记录选项,字符格式如下"1,1,3,5", 然后可以用JS设置默认值 var checklist="<%= Session["checklist"]==""?"":Session["checklist"].ToString() %>" var arycheck=checklist.split(","); jQuery(".table1 > tbody > tr").each(function (i, item) { jQuery(item).find("input[type='radio'][value='"+ arycheck[i] +"']").attr("checked",true); //或者jQuery(item).find("input[type='radio']").eq(arycheck[i]).attr("checked",true); })
liu_dashi 2013-04-11
  • 打赏
  • 举报
回复
引用 1 楼 ysn1314 的回复:
这种不适合用cache 是单个会话,不是整体域的 适合cookie或session 你就保存选中项索引或ID标识之类的 加载时判断选中
哦 针对单个用户的会话不适合用cache!由于我将选中的数据都在前端js做的,如何写入cookie或session呢?
jin225 2013-04-11
  • 打赏
  • 举报
回复
你A页面应该是有保存B页面选择的按钮吧! 那么返回的时候带回B页面的写入记录,在重新绑定。
Dotar 2013-04-11
  • 打赏
  • 举报
回复
不知道怎么弄,我觉得你只要不让B页面不刷新就可以了
闲游四疯 2013-04-11
  • 打赏
  • 举报
回复
这种不适合用cache 是单个会话,不是整体域的 适合cookie或session 你就保存选中项索引或ID标识之类的 加载时判断选中

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧