Asp.Net script in external js file

How can I use the server side of the script in an external js file to grab a link to the dom element?

The following works as intended when used as an inline script, but returns null when I go to an external js file.

$("#<%= gridResults.ClientID %>");
+5
source share
4 answers

You will need a built-in script block that creates a JavaScript variable. This block must be added before your external JavaScript file. After that, you can reference this variable in an external JavaScript file.

<script type="text/javascript">
    var grid = $("#<%= gridResults.ClientID %>");
</script>

<script type="text/javascript" src="path/to/my.js"></script>
+11
source

#<%= gridResults.ClientID %>, gridresults.ClientID asp.net.

:

<stript src="yourfile" type="text/javascript"> <!--link to external js file-->

<script type="text/javascript">
  var grid = $("#<%= gridResults.ClientID %>");

  yourfunction (grid);

</script>
+1

CssClass, , , clientID.

+1

, , . javascript ASP.NET, ASP.NET .

0

All Articles