Home » Asp.Net | Javascript | Visual Studio

Starting jQuery and Get the downloads and patches(for Visual Studio.NET 2008)

3. February 2009 by Admin 1 Comments

1.) Download install VS.NET 2008 SP1 patch

Visual Studio 2008 SP1 has the following patch to allow IntelliSense with jQuery found here.  Note: this is a patch that is applied after .NET 3.5 SP1 and Visual Studio 2008 SP1.  Information about this patch can be found here.

I did find that the vsdoc.js version must match the version of jquery in order for the intellisense to function correctly.  If the versions mismatch intellisense will not work.

2.) Download jQuery documentation library

image

3.) Download jQuery 

image

4.) Copy both 2 and 3 to your solution Scripts folder

image

5.) In your aspx reference the jquery file

<script src="Scripts/jquery-1.2.6.min.js" type="text/javascript"></script>

or

<asp:ScriptManager runat="server" ID="scriptmanager1">
    <Scripts>
        <asp:ScriptReference Path="~/Scripts/jquery-1.2.6.min" />
    </Scripts>
</asp:ScriptManager>

Some Quick Tips

  • If you are using a master page the script reference only needs to exist in the master page
  • javascript intellisense will not work in user controls by default as the user control doesn’t have a reference to the js file.  A work around (use the following at the top of the user control).  At runtime ASP.NET will not render this tag however Visual Studio will evaluate the script and provide intellisense
    <% if (false) { %>
          <script src=”../Scripts/jquery-1.2.6.min.js” type=”text/javascript”></script>
    <% } %>
  • a recommended method of including js files is to create one js file which entail will include references to any number of specific js files, then on your web page include a reference to this one single js file
    <reference path=”~/Scripts/jquery-1.2.6.min.js” />
  • a good approach is to remove the version number from the jquery files to allow easier updates to these files in the future

Path(s) for Script References

  • File-Relative Paths i.e. ../../file.js This type of path is relative to the currently loaded file.  Support - ASP.NET Web forms / MVC
  • App-Relative Paths i.e. ~/folder/file.js  Is calculated from the base of your application.  ASP.NET Web forms supports this type of path however the path must be within a scriptreference tag or select asp.net controls which have runat=”server”
  • Site-Relative Paths i.e. /folder/file.js  Is calculated from the base of your site.  Supported by ASP.NET Web forms / MVC however is not supported by Visual Studio
  • Absolute Paths i.e. http://site/folder/file.js  Supported by ASP.NET Web forms / MVC and Visual Studio

If using Visual Studio(ASP.NET Web forms) recommended to use App-Relative paths ~/folder/file.js.  If using MVC use file-relative paths.



Comments (1) -

ru551an said:

in step 5 above you have to add .js suffix to ScriptReference value

Add comment



  Country flag
biuquote
  • Comment
  • Preview
Loading







Current HOT Blog List...

These are blog entries that I have found interesting and are worth checking out.
Forbidden