zoukankan      html  css  js  c++  java
  • Asp.Net 后台注册Js脚本和引用JS文件的方法及作用位置

    Asp.Net 后台注册Js脚本和引用JS文件的方法及作用位置
    方法一:

    ClientScript.RegisterClientScriptBlock(this.GetType(),Guid.NewGuid().ToString(),"alert('Register JS')",true);


    作用位置:
    <form name="form1" method="post" action="test.aspx" id="form1">
    <div>
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="">
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="">
    <input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="">
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="">
    </div>
    <script type="text/javascript">
    //<![CDATA[
    var theForm = document.forms['form1'];
    if (!theForm) {
        theForm = document.form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script>
    
    
    //------------后台注册脚本生成在此处-------------------
    <script type="text/javascript">
    //<![CDATA[
    alert('Register JS')//]]>
    </script>
    
    
    //------------写在前台的form标签内第一个位置
    <script type="text/javascript">
    alert('Frist JS');
    </script>
    </form>

    大概在form标签内 考前的位置。
    若前台写好的js 并且是form标签内第一个标签,也会被排在后台注册的脚本之后

    方法二:

    ClientScript.RegisterStartupScript(this.GetType(),Guid.NewGuid().ToString(),"alert('Register JS')",true);

    作用位置:
    <form name="form1" method="post" action="test.aspx" id="form1">
    <div>
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="">
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="">
    <input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="">
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="">
    </div>
    <script type="text/javascript">
    //<![CDATA[
    var theForm = document.forms['form1'];
    if (!theForm) {
        theForm = document.form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script>
    //------------写在前台的form标签内最后一个位置
    <script type="text/javascript">
    	alert("Last JS")
    </script>
    //------------后台注册脚本生成在此处-------------------
    <script type="text/javascript">
    //<![CDATA[
    alert('Register JS')//]]>
    </script>
    </form>

    大概在form标签内 最后的位置。

    若前台写好的js 并且是form标签内最后的位置,也会被排在后台注册的脚本之前


    方法三:
    后台注册引用JS文件
    ClientScript.RegisterClientScriptInclude(this.GetType(),Guid.NewGuid().ToString(),"/RegisterJS.js");
    生成标签位置与方法一 (ClientScript.RegisterClientScriptBlock) 相同

    以上方法只能在form标签内生成 script 标签
    若要在head标签中生成script 用下面的方法

    方法四:
    using System.Web.UI.HtmlControls;
    
    //不可在 页面初始化之前 使用该代码
    protected override void OnInit(EventArgs e)
    {
    	base.OnInit(e);
    	//引用外部JS
    	HtmlGenericControl jsJquery = new HtmlGenericControl("script");
    	jsJquery.Attributes["type"] = "text/javascript";
    	jsJquery.Attributes["src"] = "/Scripts/jquery-1.4.2.min.js";
    	
    	HtmlGenericControl jsRegister = HtmlGenericControl("script");
    	jsJquery.Attributes["type"] = "text/javascript";
    	jsRegister.InnerText="alert('jsRegister')";
    	
    	//head标签内最后的位置
    	Header.Controls.Add(jsRegister);
    	
    	//也可自定义位置 (此处放在第一位)
    	Header.Controls.AddAt(0,jsJquery);
    }
    方法五:

    利用 服务器控件 asp:Literal,该控件没有任何回传事件,所以可放在form标签之外,

    <script>
    //后台注册脚本
    <asp:Literal runat="server" ID="lit_RegiterJS"></asp:Literal>
    </script>



  • 相关阅读:
    统计与数学必须划出界限
    Maximum likelihood from incomplete data via the EM algorithm (1977)
    Mixtures of Gaussians and the EM algorithm
    http://cs229.stanford.edu/syllabus.html
    Recurrent neural networks are very powerful, because they combine two properties
    multi-layer Recurrent Neural Network (RNN, LSTM, and GRU) for training/sampling from character-level language models
    Turning complete
    hsv hsb rgb lab
    Local Response Normalization 60 million parameters and 500,000 neurons
    Rethinking the Inception Architecture for Computer Vision
  • 原文地址:https://www.cnblogs.com/wycm/p/5338908.html
Copyright © 2011-2022 走看看