zoukankan      html  css  js  c++  java
  • 关于ASP.NET 页面生命周期个人感悟

    系统中有一个页面,需要将值赋给一个前台JS的公共变量,在前台写报错:

    <!-- 公用参数 -->
    <script language="javascript" type="text/javascript">
        var jsLangFlag,jsLocationID,jsLocationRoom,jsTranCode;
        jsLangFlag=<%=session("LangFlag") %>;
        jsLocationRoom=0;

     jsLocationID = document.getElementById(MasterPageID + 'Location_drop').value;   //在此报错,因为控件还未加载完毕。
        jsTranCode=0;   //1为订购,入库
           
    </script>

    于是想到把此JS放到PAGE_LOAD去,但同样报错,找不到对象

       Protected  Sub page_load ( )
            Response.Write("<script> jsLocationID = document.getElementById(MasterPageID + 'Location_drop').value; </script>")
        End Sub

    发现原因是一致的,因为当PAGE_LOAD的时候,控件其实还没有加载完毕,那  jsLocationID = document.getElementById(MasterPageID + 'Location_drop') 根本就找不到控件 。

    后来便把此句放到RENDER去,成功了。

       Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            MyBase.Render(writer)
            Response.Write("<script> jsLocationID = document.getElementById(MasterPageID + 'Location_drop').value; </script>")
        End Sub

  • 相关阅读:
    mybatis和spring整合
    Freemarker教程1(基本使用)
    mybatis教程6(逆向工程)
    mybatis教程4(动态SQL)
    mybatis教程5(延迟加载和缓存)
    mybatis教程2(配置文件)
    python作用域
    软件测试基础面试题
    http协议
    selenium自动化测试
  • 原文地址:https://www.cnblogs.com/withoutaword/p/2668753.html
Copyright © 2011-2022 走看看