在asp下,有时候会使用下面的代码:
<%
if request("m") = "1" then%>
<script language="javascript">
<!--
m_name[0] = "《财经》杂志 ";
//m_period[0] = 6;
init(1, 1, 1);
//-->
</script>
<%
else%>
<script language="javascript">
<!--
m_name[0] = "《财经》杂志 ";
init(0, 1, 1);
//-->
</script>
<%end if%>
<%if request("m") = "2" then%>
<script language="javascript">
<!--
m_name[1] = "《证券市场》周刊(综合刊)";
m_name[2] = "《证券市场》周刊(市场刊)";
init(1, 2, 1);
init(1, 3, 1);
//-->
</script>
<%
else%>
<script language="javascript">
<!--
m_name[1] = "《证券市场》周刊(综合刊)";
m_name[2] = "《证券市场》周刊(市场刊)";
init(0, 2, 1);
init(0, 3, 1);
//-->
</script>
<%end if%>
如果是在asp.net下,如何解决呢?
方法1(使用viewstate):(蒙斑竹鸿雪指教,试验成功)
<script language="javascript">
<!--
function howmuch2view(iselect, iview)
{
var m1, m2;
switch(iselect)
{
case 1:
m1 = 1;
m2 = 0;
break;
case 2:
m1 = 0;
m2 = 1;
break;
default:
m1 = 1;
m2 = 0;
break;
}
switch(iview)
{
case 1:
m_name[0] = "《财经》杂志 ";
//m_period[0] = 6;
init(m1, 1, 1);
break;
case 3:
m_name[0] = "《财经》杂志 ";
//m_period[0] = 6;
init(m1, 1, 1);
m_name[1] = "《证券市场》周刊(综合刊)";
m_name[2] = "《证券市场》周刊(市场刊)";
init(m2, 2, 1);
init(m2, 3, 1);
break;
default:
m_name[0] = "《财经》杂志 ";
//m_period[0] = 6;
init(m1, 1, 1);
break;
break;
}
}
howmuch2view(<%=viewstate["which2select"]%>,<%=viewstate["howmuch2view"]%>);
//-->
</script>
------------------------------------
方法2(使用panel的visible属性):
webform:
<asp:panel id="pnljsinitm1" runat="server" visible="false">
<script language="javascript">
<!--
m_name[0] = "《财经》杂志 ";
//m_period[0] = 6;
init(1, 1, 1);
//-->
</script>
</asp:panel>
<asp:panel id="pnljsinitm1n" runat="server" visible="false">
<script language="javascript">
<!--
m_name[0] = "《财经》杂志 ";
//m_period[0] = 6;
init(0, 1, 1);
//-->
</script>
</asp:panel>
<asp:panel id="pnljsinitm2" runat="server" visible="false">
<script language="javascript">
<!--
m_name[1] = "《证券市场》周刊(综合刊)";
m_name[2] = "《证券市场》周刊(市场刊)";
init(1, 2, 1);
init(1, 3, 1);
//-->
</script>
</asp:panel>
<asp:panel id="pnljsinitm2n" runat="server" visible="false">
<script language="javascript">
<!--
m_name[1] = "《证券市场》周刊(综合刊)";
m_name[2] = "《证券市场》周刊(市场刊)";
init(0, 2, 1);
init(0, 3, 1);
//-->
</script>
</asp:panel>
-----------------------------------------------
codebehind:
string strm;
try
{
strm = request.querystring["m"].trim();
}
catch
{
strm = "3";
}
switch(strm)
{
case "1":
pnljsinitm1.visible = true;
pnljsinitm1n.visible = false;
pnljsinitm2.visible = false;
//pnljsinitm2n.visible = true;
pnljsinitm2n.visible = false;
break;
case "2":
pnljsinitm1.visible = false;
pnljsinitm1n.visible = true;
pnljsinitm2.visible = true;
pnljsinitm2.visible = false;
//pnljsinitm2n.visible = false;
break;
default :
pnljsinitm1.visible = false;
pnljsinitm1n.visible = true;
pnljsinitm2.visible = false;
//pnljsinitm2n.visible = true;
pnljsinitm2n.visible = false;
break;
}
中国最大的web开发资源网站及技术社区,