0

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.

rickyProgrammer
  • 1,177
  • 4
  • 27
  • 63
  • 1
    Probably because $160('#<%=grdLeasingReport1.ClientID%>') is not JS, and will not run in a JS file. – Mark Jun 07 '16 at 03:58
  • $160('#<%=grdLeasingReport1.ClientID%>') this is Server control ID , and can use after rendering all page. so you can put this piece of code an external js but you must add the external JS link at the bottom of aspx page – Nazir Ullah Jun 07 '16 at 04:16
  • I see. So that line of code is not a js code, so are there ways to put that line of code in the ecternal js file? – rickyProgrammer Jun 07 '16 at 05:21
  • hi @Nazir actually the external js is already linked in the master page where this page is using. and i put the code in that external js file – rickyProgrammer Jun 07 '16 at 05:23
  • actully some pages render before , after loading entire master page, that's why the code can't access the server control ID , for testing purpose an external js page create and put the link on bottom of this aspx page , – Nazir Ullah Jun 07 '16 at 05:58

1 Answers1

1

<%=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.

Community
  • 1
  • 1
RDJ
  • 191
  • 1
  • 7