How to Use Visual Studio jQuery IntelliSense Supported Through Hotfix

by Bill Beckelman 8. November 2008 10:14

Jeff King, Program Manager for Visual Studio Web Tools blogged VS2008 SP1 Hotfix to Support "-vsdoc.js" IntelliSense Doc Files on Friday. The HotFix (VS2008 SP1 only) allows Visual Studio to find "-vsdoc.js" files that have commenting for IntelliSense in the same folder as a script file linked to from your document. In this post I am going to show you how to get IntelliSense working once the HotFix is installed in both a normal aspx page as well as an ASP.NET MasterPage.

FolderTree 

So if you just link to the jquery-1.2.6.js file like below, Visual Studio will find the jquery-1.2.6-vsdoc.js file that is in the same folder and use it for IntelliSense.

Markup from head of Standard aspx page:

<head runat="server">
<title>jQuery IntelliSense</title>
    
     <script src="_assets/js/jquery-1.2.6.js" type="text/javascript"></script>
</script>        
</head>

What if you want IntelliSense and you link to the jQuery file from an ASP.NET MasterPage though? Well, the best I can figure you still have to hack things a little as Visual Studio will not provide IntelliSense in your child pages in this situation. Follow the code below for a workaround.

Markup from MasterPage:

<head runat="server">
    <title></title>
    
    <script src='<%# ResolveUrl("~/_assets/js/jquery-1.2.6.min.js") %>' type="text/javascript"></script>    
    
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>

     Notice that I am using databinding when resolving the path of the jQuery file. See this post for an explanation. Also notice I am linking to the minified file.

Markup from child aspx page:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

     <% if(false) { %>
            <script src="_assets/js/jquery-1.2.6.js" type="text/javascript"></script>
     <% } %>

</asp:Content>

image

By using the script tag hack, Visual Studio will find the file to use for IntelliSense, however when the page is rendered the script evaluates to false and the jQuery file from the MasterPage is not overridden. This method works well unless of course you need to debug the jQuery file. In that case, just switch the file linked to in the MasterPage to the non minified version. This method is nice though because you don't end up forgetting to switch to the minified file when you deploy.

Please let me know in the comments if you find or know of a better way.

Share this post:    kick it on DotNetKicks.com

Comments

Comments are closed

Powered by BlogEngine.NET 1.4.5.7
Theme by Mads Kristensen


About Me

I live and work in Salt Lake City, Utah. My background is in aviation. I have a degree in Aeronautical Science from Embry-Riddle Aeronautical University in Prescott, AZ. I have worked as a commercial airline pilot and most recently as a technical advisor for a charter airline.

Month List