jQuery Ajax Get calls fail in IE (Internet Explorer) but work in Firefox, Chome, Safari.. why?

You may have come across the situation where you are making a jQuery AJAX GET request to update part of your page with changing content, but it never updates or just returns blank content.

This issue has been around a long time, since first use of Ajax calls via XMLHTTP, but still causes headaches for people trying to debug the problem now.

What it actually comes down to is that the ‘Get’ call is working correctly, but Internet

Explorer (IE) caches the response, so you never get the updated results from the server.

What are the options:

  • 1) Use POST rather than GET – although this is not semantically correct, you should only POST when modifying contents on the server, technically there really is not much difference.
  • 2) (Preferred) You can disable caching globally using $.ajaxSetup(), for example:

    $.ajax
    Setup({ cache: false });
    This appends a timestamp to the querystring when making the request. To turn cache off for a particular $.ajax() call, set cache: false on it locally, like this: $.ajax({
    cache: false,
    //other options...
    });

Firefox 11 Memory Leak

I have always been a fan of Firefox and encouraged other developers to use it, addons such as Firebug and YSlow are simply essential tools for anything more than your most basic web page, and will even help with those. Neither the developer tools in Chrome, Safari or IE can really compete.

There certainly does seem to be an issue with the latest version of Firefox though regarding Continue reading

MVC3 Razor – jQuery – Visual Studio != Intellisense

I wondered where my intellisense had gone for jQuery with MVC3 and Razor. Anyway there is a fix for it:

Add the following to your view (with the jQuery vsdoc version you have:

@if (false) { <script src="~/Scripts/jquery-1.5.0-vsdoc.js" type="text/javascript"></script> }

The if-statement prevents the script tag from being rendered into the html source code.

Grab jQuery 1.5.0 vsdoc from here -> http://damianedwards.com/files/jquery/jquery-1.5-vsdoc.js

Cannot have multiple items selected in a DropDownList (ASP.Net)

Nasty problem. Lesson learnt.

I could not figure out why I was seeing this error, clearselection, setting index -1 etc, nothing worked when trying to set a dropdownlist selected value from code behind.

Turns out it was because I was adding a ListItem to multiple dropdownlists without instantiating a new one for each dropdownlist. This caused all the problems I was seeing.

For every Dropdownlist, create a new instance of the ListItem object before adding it – do not share it accross controls.

Firefox refresh page retaining checkbox/radiobutton values

I had a page which uses codebehind Page_Load and (!IsPostBack) to setup all the controls on the page depending on what was being loaded. This worked fine, apart from when I refreshed the page (F5) in Firefox 3.5 – IE was okay.

Firefox seems to retain all the input selections – eventhough from the code behind I was ressetting them.

The only way I found to resolve this was to call a reset on the form (actually in my Master page) in the document ready function of JQuery which solves the problem.

$(document).ready(function() {

$(“#<%= (form1.ClientID) %>”)[0].reset();

});

Problem with ASP.Net & Radiobuttons in repeaters/datalists/datagrids all being selectable

RadioButtons place on a page inside a repeating control (repeater/datalist/datagrid), you set the group but they are still all individually selectable.

I have come across this problem before, which was fixed using some client side script added to the radiobuttons, but this had to be done for each radiobutton group as I added them and was a bit of a pain.

I have recently found a much better solution here -> http://www.codeproject.com/KB/webforms/How_group_RButtons.aspx

Works perfectly well. Unstructions:

1) Just download the zip file at the top of the page.

2) Unzip and place the file (GroupRadioButton.dll) into your bin folder.

3) Add a reference to the assembly into your web.config or .aspx page as below:

<%@ Register TagPrefix=”vs” Namespace=”Vladsm.Web.UI.WebControls” Assembly=”GroupRadioButton” %>

Use the control on your page as you would a RadioButton

<vs:GroupRadioButton id=”MyRbn” runat=”server” GroupName=”MyRbnGrp” />

Thats it. Brilliant 🙂

Kudos to Vladimir Smirnov.

ASP.Net UpdatePanel breaks Javascript/JQuery e.g. Slimbox, Tooltip…

After using ASP.Net Ajax components such as an updatepanel on your page you may see that some of your Javascript/JQuery functions do not seem to work once a partial page update has been done. This is because thanks to the partial page update those items contained within it have been reloaded but no functions have been rebound to them.

I have used 2 solutions for this, one is JQuery Live Query. You can use this to simply rebind to any item reloaded for example I used this to rebind the elements I had previously set for Slimbox and set the rel=lightbox attribute for them:

$(“a[rel^=’lightbox’]”).livequery(function() {
$(this).slimbox();
});

This finds any anchor element with the rel=”lightbox” tag and binds the slimbox function.

Alternativly to this you can replace the

‘$(document).ready(function() {

// do stuff

});

with

function pageLoad(sender, args)
{
// do stuff

if (args.get_isPartialLoad())
{
//Specific code for partial postbacks can go in here.
}
}

But be aware this can only be used once on the document, if you need to do this in multiple places use:

Sys.Application.add_load(function() {

// do stuff

});

Visual Studio – Attach to running local web site process to debug (and cannot see w3wp.exe?)

I had this problem where I wanted to attach my Visual Studio debugger to and already running website on local host.

From a bit of Googleing I found the process I needed to attach to was the IIS worker process called w3wp.exe, but this was not in my list. I noticed if I refreshed the site and then looked quickly in the process list it was there but then dissapeared shortly after – so a timeout I guessed.

This is what was happening, so I needed to stop it from timing out or at least delay it.

The answer was to change a setting in the applicaiton pool – ‘Shutdown Time Limit’.

Solution Summary:
– Goto IIS and find the website or application you want to modify.
– Click advanced settings to find the applicaiton pool it is using (or as I did create a new application pool and assign this website to use it)
– Goto your application pool list – selected advanced settings
– Change the ‘Shutdown Time Limit’ to something like 1000 (seconds) its default is 90

w3wp.exe should now hang around long enough to attach to it with the debugger 🙂