jQuery Intellisense in VS 2008 not working with ajax ToolkitScriptManager - asp.net

I've followed all the steps to get intellisense working for jQuery in VS 2008 SP1 (with the vsdoc hotfix). It works when I reference jQuery inside an asp:ScriptManager control like so:
<asp:ScriptManager runat="server">
<scripts>
...
</scripts>
</asp:ScriptManager>
But I'm using ajax ToolkitScriptManager instead and the intellisense doesn't seem to work when using this control. It offers some better features so I'm not willing to live without it.
It looks like the VS team only programmed the jQuery intellisense to look for asp ScriptManager controls and not ToolkitScriptManager. Has anyone found a workaround for this specific problem?
Cheers

Wows, I, had the same problem and used the following method to trick Visual Studio:
<% if(false) { %>
<script src="/scripts/jquery-1.3.2.js" type="text/javascript"></script>
<% } %>
The script tag will never be rendered but VS interprets it and enables intellisense.

If the file is contained in your project with a -vsdoc.js at the end, IntelliSense should work. Rick Strahl has a great post about this at http://www.west-wind.com/Weblog/posts/536756.aspx

A different question: why are you putting the JQuery library in the script manager?
The script manager can do some cool things, like compress the javascript files for you -- but that only works if the JavaScript is in a resource file.
Also, using the ScriptManager adds a bunch of extra JavaScript that will not be downloaded by the client (all of the Microsoft AJAX libraries). Which is fine so long as you are using the Microsoft AJAX Toolkit, but is a lot of extra load if you are not.
EDIT: if you want a better relative position get JQuery from Google Code. You can read about it here: http://code.google.com/apis/ajaxlibs/

Related

How to make Web forms custom validator to use Ajax CDN

When using ASP.NET AJAX, you can point to an external CDN when declaring the script manager
for example
<asp:scriptmanager runat="server" enablecdn="true"></asp:scriptmanager>
However, I have noticed that if there is a user control on the same page which uses a custom validation, the framework still generates this code
/ScriptResource.axd?d=9yV7lSty3eIjRHuyQO6mUIbifRXho5yOz18Mb9LNzPDMVDZt5gucvycOn0YjgTb-p_rRW2V1ZDDrrpuaOC7nExHrA_4WmsL5gsOQ0m2syuuMp2VfpWep-II1V1zy1jHYfkvYfBRkGo_2LqqJh0Gung2&t=fffffffff11c85e0
which points to a local resource. I want this to point to the same CDN instead
Any ideas how to fix this?
I figured out how to fix/resolve this if it is of any help.
Basically I needed to disable 'AjaxFrameworkMode' property of the ScriptManager as shown below
<asp:ScriptManager ID="ScriptManager1" EnableCdn="true" runat="server" AjaxFrameworkMode="Disabled"> </asp:ScriptManager>
The AjaxFrameworkMode property adds two new modes to ScriptManager’s
behavior. Enabled (the default, and the same behavior as before),
Explicit (does not include any scripts by default but still assumes
Microsoft Ajax is to be utilized), and Disabled (does not include any
scripts by default and does not assume Microsoft Ajax will be used). For more details read more...

AJAX Control Toolkit Loading All Scripts

I have a bit of a weird problem I can't seem to fix. I am using the AJAX Control Toolkit's calendar extender on some of my pages. Despite the information I've found via the web I can't seem to get it working with a regular ScriptManager control, it only works with a ToolkitScriptManager. However I've noticed that when the page loads it adds some 84 script files for every possible control script provided by the toolkit:
Is this the expected behaviour, and can I turn it off? I only need it to load the relevant scripts to handle the calendar extender.
In current version of ACT you can group extenders in bundle and specify which bundles you need to include.
Add AjaxControlToolkit.config file to project like here Codeplex AjaxControlToolkit.config, add new controlBundle entry to this file for CalendarExtender like this:
<controlBundle name="Calendar">
<control name="CalendarExtender"></control>
</controlBundle>
and specify this bundle in ToolkitScriptmanager control:
<ajaxToolkit:ToolkitScriptManager runat="server" CombineScripts="true"
ScriptMode="Release" >
<ControlBundles>
<ajaxToolkit:ControlBundle Name="Calendar" />
</ControlBundles>
</ajaxToolkit:ToolkitScriptManager>
Use ControlBundles to solve this, follow this step about ControlBundles on how to do it.

How to use jQuery on my page?

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:
Thanks.
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.

Calendarextender is not displayed with masterpages

I'm working with masterpages and after reading a lot of answers I can't find why my calendarextender doesn't appear
Here is my code
http://pastebin.com/m789f935e
did you check the setting in the webconfig file . do you have all the required settings for ajax . ?
Have you tried changing the TagPrefix in the
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
directive to something other than asp? Not sure how well referencing more than one assembly for a single TagPrefix is supported.
The info here and here sort of backs me up...sort of. Give it a shot and let us know how it goes.
I see you have more than one ScriptManager tag... one in the Master page and one in your VerFavoritos.aspx page. I suggest you add one ScriptManager in the Master, place it right after the tag and before anything else in the Master page. Remove any ScriptManager tags from the VerFavoritos.aspx page.
Hope this helps.
Do you have the AJAX Control Toolkit .dll in your References?
The entry in the web.config you are looking for is something along this line:
<add assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagPrefix="AjaxControlToolkit"/>
When this happens you can use the calendar extender with syntax like:
<AjaxControlToolkit:CalendarExtender ... />
Rebor.
My application have a page that displays a ModalPopUp (the modal pop up pf ajax toolkit).
Inside the PopUp i put a calendarExtender, but the calendar appears behind the PopUp, so, to solve it i need to associate my Calendar to a CSS, like this:
<cc1:CalendarExtender ID="txtProximoContato_CalendarExtender" runat="server" PopupButtonID="imgCalendarProxContato"
Enabled="True" CssClass="CalendarPopup" TargetControlID="txtProximoContato">
</cc1:CalendarExtender>
and the CSS class
.CalendarPopup
{
z-index: 10500 !important;
}
I dont know if it is your problem, but i hope this help you
To be honest the Ajax Control Toolkit has been superceded by things like jQuery. Seriously consider using jQuery UI or extjs instead - I've always found this library to buggy and badly supported.
I copied/pasted your code almost exactly as it was and the calendar extender appeared.
Follow these steps exactly and it should work for you
Uninstall and reinstall AJAX 1.0.
From within VS 2005, create an "AJAX Enabled Website" instead of a regular website (VS 2008 automatically creates this type of website).
Add a reference to AjaxControlToolkit and it should work.
If you are still having trouble
Send me your solution. I'll correct it and send it back to you.

How do you get JavaScript/jQuery Intellisense Working in Visual Studio 2008?

I thought jQuery Intellisense was supposed to be improved with SP1. I even downloaded an annotated version of jQuery 1.2.6, but intellisense will not work in a separate jscript file. I have the jQuery library referenced first on my web page in the <head> tag. Am I doing anything wrong?
At the top of your external JavaScript file, add the following:
/// <reference path="jQuery.js"/>
Make sure the path is correct, relative to the file's position in the folder structure, etc.
Also, any references need to be at the top of the file, before any other text, including comments - literally, the very first thing in the file. Hopefully future version of Visual Studio will work regardless of where it is in the file, or maybe they will do something altogether different...
Once you have done that and saved the file, hit Ctrl + Shift + J to force Visual Studio to update Intellisense.
There is an officially supported jQuery documentation JavaScript file for Visual Studio 2008. This file is only an interim fix until Microsoft releases a hotfix that will more adequately address the issue.
Embedded in ASPX:
<% if (false) { %>
<script src="jquery-1.2.6-vsdoc.js" type="text/javascript"></script>
<% } %>
Embedded in JavaScript:
/// <reference path="jquery-1.2.6-vsdoc.js" />
Pick it up here: jquery-1.2.6-vsdoc.js
References:
Rich Intellisense for jQuery
Scott Hanselman - ASP.NET and jQuery
You'll want to look at this link:
http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx
UPDATE: There is a new HotFix for Visual Studio 2008 and a new jQuery Intellisense Documentation file that brings full jQuery Intellisense to VS'08. Below are links to get these two:
http://blogs.msdn.com/webdevtools/archive/2008/11/07/hotfix-to-enable-vsdoc-js-intellisense-doc-files-is-now-available.aspx
http://blogs.msdn.com/webdevtools/archive/2008/10/28/rich-intellisense-for-jquery.aspx
For inline JavaScript, use:
/// <reference path="~\js\jquery-vsdoc.js"/>
Note the back slashes.
This will not work:
/// <reference path="~/js/jquery-vsdoc.js"/>
You shouldn't need to actually reference the "-vsdoc" version. If you put the jquery-1.2.6-vsdoc.js in the same directory as jquery-1.2.6.js then Visual Studio will know to covert a jquery-1.2.6.js reference to jquery-1.2.6-vsdoc.js.
I think that will actually work for any file.
Hmmm... that gives a good workaround for another question on this site...
Edit: This feature only works with VS2008 Service Pack 1.
If you are including the annotated jQuery file in your source solely for intellisense, I recommend leveraging preprocessor directives to remove it from your view when you compile. Ala:
<% #if (false) %>
<!-- This block is here for jquery intellisense only. It will be removed by the compiler! -->
<script type="text/javascript" src="Scripts/jquery-1.3.2-vsdoc.js"></script>
<% #endif %>
Then later in your code you can really reference jQuery. This is handy when using the Google AJAX Libraries API, because you get all the benefits Google provides you, plus intellisense.
Here is a sample of using the Libraries API:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2", { uncompressed: false });
</script>
jQuery Intellisense in Visual Studio 2008
If you want to pick up the Intellisense file from the Microsoft CDN you can use:
/// <reference path="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1-vsdoc.js" />
Make sure you're not using a minimized jQuery file.
Use Ctrl + Shift + J to make it work after adding JavaScript files to the project.

Resources