简体   繁体   中英

How to Make Internal Javascript in ASP.NET external

I have code in ASP.NET web form that make gridview header fixed.

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script src="jquery/JQueryUICalendar/js/gridviewScroll.min.js"  type="text/javascript"></script>

<script type="text/javascript">
    var $160 = jQuery.noConflict();
    $160(document).ready(function () {
        gridviewScroll();
    });

    function gridviewScroll() {
        $160('#<%=grdLeasingReport1.ClientID%>').gridviewScroll({
            width: 1080,
            height: 350,

        });
    }
</script>

This is inline with the aspx WITH GRIDVIEW which is using that as reference. I want to make it in external file along with my other js scripts, but it is not working after doing that.

<%=grdLeasingReport1.ClientID%>

is not Javascript but code from .Net.

That's probably why it's inline javascript. If it's possible, and not a breach of security, one way to force the issue is to make the clientid part of the url querystring, then grab it with javascript to use in your gridviewScroll function.

Use this as reference for taking on this task: How can I get query string values in JavaScript?

as for putting the grdLeasingReport1.ClientID in the url querystring, it will just depend on how you "arrive" at the page in question. I don't know if this will help; but it's one way to pull the javascript from inline and into a linked .js file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM