2

I'm following this tutorial but it doesn't tell me how to run this jQuery script. Since this script will be run pretty much everywhere, I should attach this script to the Masterpage right, but how?

I guess what I'm asking is, what HTML tag do I need to reference the jQuery script, and where to put the jQuery code.

I have this library already in my project: alt text

Thanks.

Frankie
  • 24,627
  • 10
  • 79
  • 121
Sergio Tapia
  • 40,006
  • 76
  • 183
  • 254
  • 4
    Why the downvotes? I believe this a perfectly reasonable question. – Russell Aug 12 '10 at 23:30
  • 1
    @Sergio Tapia - you might want to link the tutorial you're looking at. – Franci Penov Aug 12 '10 at 23:32
  • 1
    Not that I've voted on this but unfortunately Russell our voting intentions aren't dependent on what *you* think is reasonable. –  Aug 12 '10 at 23:34
  • No but when I refer to reasonable, I was refering to the question meeting the requirements of the FAQ. – Russell Aug 12 '10 at 23:36
  • 1
    I am one of those who voted down. The reason is that it's also an ASP specific question and the technology wasn't mentioned anywhere... Unfortunately I am not used to the Visual Studio and so I wasn't able to guess the technology from the screenshot. – tux21b Aug 12 '10 at 23:43
  • 2
    @tux21b so move along quietly, no need to downvote. Last time I looked an inability to guess an unfamiliar technology was not a valid purpose of downvoting. – Simon Fox Aug 12 '10 at 23:50
  • 2
    Comments are intended to be used for clarification, and voting down for misinformation. The PO did not have any misinformation in the question. A comment to request clarification would be more helpful to the PO (and others) so they have a greater chance of an answer to their questions. – Russell Aug 12 '10 at 23:51

1 Answers1

3

jQuery is a client-side scripting tool. ASP .Net is a server-side language.

You are correct, to add a reference to jQuery for all pages it is a good idea to use a master page for this purpose.

In the master page, you simply add the HTML script reference to the master page:

<@ MasterPage .... >

<html>
<head>
  <script src="../Scripts/jquery-1.4.1.js"></script>
</head>
<body>
 <asp:ContentPlaceHolder id="Content" />
</body>
</html>

Add a script element for each of the jQuery scripts. Make sure the jquery-1.4.1.js is the first referenced though.

Also make sure you use the <script></script> instead of <script/> due to some browser issues.

Some newer Visual Studio MVC project files do this script referencing for you (as Lenial mentioned), and this may be easier.

cHao
  • 84,970
  • 20
  • 145
  • 172
Russell
  • 17,481
  • 23
  • 81
  • 125