在我这种情况下,如何使用asp.net中的Cache 我在做一个问卷调查功能,在页面B中有一个Repeater控件,其中嵌套有RadioButtonList控件。在选项中我随意选几个。这时候我会跳转到页面A中,然后再回到页面B。我想要之前选择的几个选项仍然是选定状态。想到要用Cache来做,我没使用过Cache,不知到在这种业务中如何实现?ASP.NETCacheRadiobuttonlistjavascript 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这种不适合用cache 是单个会话,不是整体域的适合cookie或session你就保存选中项索引或ID标识之类的 加载时判断选中 你A页面应该是有保存B页面选择的按钮吧! 那么返回的时候带回B页面的写入记录,在重新绑定。 哦 针对单个用户的会话不适合用cache!由于我将选中的数据都在前端js做的,如何写入cookie或session呢? 1\可以用层来显示隐藏来表现,这样就不存在cookie或session2\用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);}) 又是你啊 呵呵!这个功能做的我头疼 tmd!用你这种方式的话,比如我有5个radiobuttonlist,我开始只选其中的两个,这时候arycheck[i] 和 jQuery(item).find 对不上了吧就 <%@ 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> 这种方式是可以,不过你没明白我的意思。比方你开始只选了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))} 关于ASP.NET页面缓存的一些问题 要做个个人网站,要求我在下面给出了,高手能告诉我这样的网站要做些什么模块,尽量清楚点,谢谢 100分求,谁告诉我个c#开源网店系统? asp.net(vb)实现无刷新DropDownList联动???高手指教! javascript点击按钮退出frameset 多条件判断出问题 给模式窗口传值的长度有限制吗? jQuery加载load()方法遇到的问题 ASP.NET论坛挺有节日气氛的嘛,偶也来助助兴,各位大哥大姐,老少爷们大家辛苦了! 在EF中数据库联机如何给定密码? 页面数据采集--求正则 高分求教一小段代码
适合cookie或session
你就保存选中项索引或ID标识之类的 加载时判断选中
那么返回的时候带回B页面的写入记录,在重新绑定。
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);})
<%@ 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>
在点下一步前就对映好,不选也要留空
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))
}