C#代码
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request.QueryString["theme"] != null)
{
switch (Request.QueryString["theme"])
{
case "Blue":
Page.Theme = "BlueTheme";
break;
case "Pink":
Page.Theme = "PinkTheme";
break;
}
}
}
JavaScript代码
<script type="text/javascript">
function changeTheme() {
var theme = document.getElementById("ddlTheme").value;
var url = window.location.href.replace(/(^\s*)|(\s*$)/g, "");//获取去处两边空格之后当前url
if (url.indexOf("?") == -1) { //查找?的索引位置
url += "?theme=" + theme;
} else if (url.indexOf("?") == url.length - 1) {
url += "theme=" + theme;
} else {
url += "&theme=" + theme;
}
window.location = url;//重新加载当前页
}
</script>