Framework Madness!

And other adventures C# and asp.net …

Posts Tagged ‘JavaScript

Global AJAX Request Error Display for Asp.net MVC 2

leave a comment »

 

So you thought you might like to,
Go to the show.
To feel the warm thrill of confusion,
That space cadet glow.
Tell me is something eluding you, sunshine?
Is this not what you expected to see?

 

Ever get that kind of feeling when trying to debug server side request errors using AJAX (MS AJAX or jQuery) in MVC. I mean, on a normal posts that fails you get the nice yellow error screen that says “Hey you …” and “Bring on the (Stack Trace)!” and makes your wonder “Is there anybody out there?”. We’ll no more. Here’s a basic script you can just hook up while building/debugging your app that if you get a server side error making an AJAX request you’ll get the same effect as a full post back.

 

Code Snippet
/// <reference path="../Common/jquery-1.4.1-vsdoc.js" />
/// <reference path="../Common/MicrosoftAjax.js" />

$(document).ready(function () {

    //replace the screen with the response error

    //jQuery —————————————————–
    $(document).ajaxError(function (event, request, settings) {

        $(document.body).html(request.responseText);

    });

    //MS AJAX —————————————————-
    function OnWebRequestComplete(executor, eventArgs) {

        if (executor.get_statusCode() === 500) {

            $(document.body).html(executor.get_responseData());
        }
    }

    Sys.Net.WebRequestManager.add_completedRequest(OnWebRequestComplete);

});

Advertisements

Written by Lynn Eriksen

March 30, 2010 at 12:13 am

Posted in Uncategorized

Tagged with ,

Visual Studio 2010 RC – Problem with parseInt/parseFloat when Using JavaScript Intellisense

leave a comment »

Posted on Connect, but I wanted to see if anyone else had this problem. Here’s the description:

When using a call to ‘parseInt’ or ‘parseFloat’ methods intellisense will become slow, and in the case of jQuery methods not work at all. Commenting out or removing the ‘parseInt’ and/or ‘parseFloat’ call resolves the issue.

Here is the code sample that busts:

Code Snippet
  1. /// <reference path="jquery-1.3.2-vsdoc.js" />
  2.  
  3. $(document).ready(function () {
  4.     //due to parseInt or parseFloat being called intellisense will slow or not work
  5.     //if both are commented out it will work properly, if one if called it slows or breaks
  6.  
  7.     var result1 = parseInt("10", 10);
  8.     var result2 = parseFloat("10");
  9.  
  10.  
  11.     //try using intellisense below this comment – it is very slow
  12.  
  13.  
  14.  
  15. });

If it fails for you too, then follow this link to Connect and confirm. The VS 2010 JavaScript intellisense is great, and we want to help get as many bugs stomped out before the final release.

Written by Lynn Eriksen

February 11, 2010 at 5:56 pm