怎样使页面刷新后保存保持Ul菜单展开 asp.net
我把左边的菜单写成了用户自定义控件,然后放到母版页里面去,
当点击子节点,显示相关数据在右边,同时页面会刷新(整个母版页都刷新了)
刷新后,子菜单收起来了,我需要它还是展开的。我用什么方法可以使得菜单在刷新后,仍然保持展开状态?
我不是使用的treeview,而是使用的Repeater。而子菜单连接到右边的数据,是通过
<ahref="<%=Dir %>default.aspx?id=<%#Eval("ItemCategoryID") %>">XXX</a>
------解决方案--------------------用js +css样式可以实现
------解决方案--------------------if(!IsPostBack)
rpt.DataBind();
最好用Ajax做局部刷新
------解决方案--------------------用Cookie吧
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style type="text/css">
body {font:12px Tahoma, sans-serif;color:#4D4D4D;margin:0px; text-align:center}
a{color:#4D4D4D;text-decoration:none}
a:hover{color:#AD0000;text-decoration:none}
#menu {width:160px;margin:0px;padding:0px;text-align:left;list-style:none;border:1px solid #B0D4ED}
#menu .item {margin:0px;padding:0px;list-style:none; text-align:center}
a.title:link,a.title:visited,a.title:hover {display:block;height:30px;line-height:30px; margin-top:1px;background:#E1F2FD;border-top:1px solid #B0D4ED;border-bottom:1px solid #B0D4ED;font-weight:bold;}
#menu .item ul {margin:0;list-style:none;display:none;text-align:center}
#menu .item ul li {height:24px;line-height:22px;border-bottom:1px solid #BFDBEE;margin:0 20px}
</style>
<script language="javascript" type="text/javascript">
// --- 获取ClassName
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var j = 0; j < elem.length; j++) {
var classes = elem[j].className;
if (myclass.test(classes)) retnode.push(elem[j]);
}
return retnode;
}
// --- 隐藏所有
function HideAll() {
var items = document.getElementsByClassName("optiton");
for (var j=0; j<items.length; j++) {
items[j].style.display = "none";
}
}
// --- 设置cookie
function setCookie(sName,sValue,expireHours) {
var cookieString = sName + "=" + escape(sValue);
//;判断是否设置过期时间
if (expireHours>0) {
var date = new Date();
date.setTime(date.getTime + expireHours * 3600 * 1000);
cookieString = cookieString + "; expire=" + date.toGMTString();
}
document.cookie = cookieString;
}
//--- 获取cookie
function getCookie(sName) {
var aCookie = document.cookie.split("; ");
for (var j=0; j < aCookie.length; j++){
var aCrumb = aCookie[j].split("=");
if (escape(sName) == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
window.onload = function() {
var show_item = "opt_1";
if (getCookie("show_item") != null) {
show_item= "opt_" + getCookie("show_item");
}
document.getElementById(show_item).style.display = "block";
var items = document.getElementsByClassName("title");
for (var j=0; j<items.length; j++) {
items[j].onclick = function() {
var o = document.getElementById("opt_" + this.name);
if (o.style.display != "block") {
HideAll();
o.style.display = "block";
setCookie("show_item",this.name);
}
else {
o.style.display = "none";