ASP教程 PHP教程 JSP教程 CGI教程 XML教程
  • ASP.NET教程
  • JAVA教程
    当前位置:教程 > 程序设计 > ASP.NET教程 > 正文

    ASP.NET下根据QueryString决定使用哪块&#106avascript的两种方法

    编辑:教程网 来源:网络 时间:2011年09月02日 15:49
    在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] = "《证券市场》周刊(市场刊)";
  • 原文来自 教程网 转载请注明:http://www.websmill.com/chengxu/aspnet/21099.html

  • 上一篇:改变 PropertyGrid 控件的编辑风格(2)——编辑多行文本
  • 下一篇:比较XML数据存取APIs(续)