Asp. NET to decide which JavaScript to use according to QueryString two ways:)
Last Update:2017-02-28
Source: Internet
Author: User
asp.net
under ASP, the following code is sometimes used:
<%
If Request ("M") = "1" then%>
<script language= "JavaScript" >
<!--
M_name[0] = "Caijing magazine";
M_period[0] = 6;
Init (1, 1, 1);
-->
</script>
<%
Else%>
<script language= "JavaScript" >
<!--
M_name[0] = "Caijing magazine";
Init (0, 1, 1);
-->
</script>
<%end if%>
<%if request ("M") = "2" then%>
<script language= "JavaScript" >
<!--
M_NAME[1] = "Securities Market" weekly (comprehensive issue);
M_NAME[2] = "Securities Market" weekly (market issue);
Init (1, 2, 1);
Init (1, 3, 1);
-->
</script>
<%
Else%>
<script language= "JavaScript" >
<!--
M_NAME[1] = "Securities Market" weekly (comprehensive issue);
M_NAME[2] = "Securities Market" weekly (market issue);
Init (0, 2, 1);
Init (0, 3, 1);
-->
</script>
<%end if%>
if it is under the ASP.net, how to solve it?
Method 1 (using ViewState): (Mongolian bamboo-hung Xue Advice, successful test)
<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] = "Caijing magazine";
M_period[0] = 6;
Init (M1, 1, 1);
Break
Case 3:
M_name[0] = "Caijing magazine";
M_period[0] = 6;
Init (M1, 1, 1);
M_NAME[1] = "Securities Market" weekly (comprehensive issue);
M_NAME[2] = "Securities Market" weekly (market issue);
Init (M2, 2, 1);
Init (M2, 3, 1);
Break
Default
M_name[0] = "Caijing magazine";
M_period[0] = 6;
Init (M1, 1, 1);
Break
Break
}
}
Howmuch2view (<%=viewstate["Which2select"]%>,<%=viewstate["Howmuch2view"]%>);
-->
</SCRIPT>
------------------------------------
Method 2 (using the Visible property of the Panel):
WebForm:
<asp:panel id= "pnlJsInitM1" runat= "Server" visible= "False" >
<script language= "JavaScript" >
<!--
M_name[0] = "Caijing magazine";
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] = "Caijing magazine";
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] = "Securities Market" weekly (comprehensive issue);
M_NAME[2] = "Securities Market" weekly (market issue);
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] = "Securities Market" weekly (comprehensive issue);
M_NAME[2] = "Securities Market" weekly (market issue);
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
}