Asp. NET to decide which JavaScript to use according to QueryString two ways:)

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

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.