Category Archives: JavaScript

JavaScript: Extending String to Have startsWith and endWith Functions

Here’s two prototype functions you can add to your JavaScript to give you “startsWith” and “endsWith” functions: if (!String.prototype.startsWith) {     String.prototype.startsWith = function (str) {         return this.slice(0, str.length) == str;     }; } … Continue reading

Posted in JavaScript | Leave a comment

jQuery: Global AJAX Error Handler

Here’s a quick and dirty way to handle AJAX errors globally if you are using jQuery: $(document).ready(function () {     $.ajaxSetup({         error: function (x, e) {             if (x.status == … Continue reading

Posted in JavaScript, jQuery | Leave a comment

JavaScript: Quickly Trim the Last Character from a String

When developing web applications, you undoubtedly have wanted to remove the last character from a string (such as a URL or application path)  in your JavaScript code. Here’s a quick way to get it done using the JavaScript function slice(): var applicationPath … Continue reading

Posted in JavaScript | Leave a comment

JavaScript, UTF-8 Encoding: escape() vs. encodeURIComponent()

ASP.Net web applications default to UTF-8 encoding.  Now, if you are using JavaScript to create or change URLs, you might run into an issue with the way the function “escape()” encodes characters if you are handling the decoding in your … Continue reading

Posted in ASP.Net, C#, JavaScript | Leave a comment

Sys.WebForms.PageRequestManagerServerErrorException in FireFox with MSFT Ajax

If you encounter this error while navigating away from an AJAX-enabled page with a non-IE browser, you can silence it with the following JavaScript: if (!document.all) //non-ie { window.onbeforeunload = function() { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ignoreOnEndRequest); } } function ignoreOnEndRequest(sender, e) { err … Continue reading

Posted in ASP.Net, C#, FireFox, JavaScript | 1 Comment

Using the PageRequestManager in ASP.Net AJAX (ATLAS)

In your java script:: var postBackElem; Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler); Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler); function BeginRequestHandler(sender, args) { postBackElem = args.get_postBackElement(); } function PageLoadedHandler(sender, args) { var c = ‘panels created: ‘; var u = ‘panels updated: ‘; for(var i=0;i c += args.get_panelsCreated()[i].id + ‘, ‘; … Continue reading

Posted in JavaScript, Microsoft AJAX | Leave a comment

FireFox caches JavaScript state

Firefox uses in memory caching for JavaScript and can cause strange errors in your MSFT ASP.NET Ajax applications. Try adding this to your load event to prevent those errors: if (Request.Browser.MSDomVersion.Major == 0) // Non IE Browser?) { Response.Cache.SetNoStore(); // … Continue reading

Posted in C#, FireFox, JavaScript | Leave a comment

Automatically close a window in FireFox

You may run into an issue trying to close a created window in FireFox, this javascript usually does the trick on your close link: window.open(’java script:window.close();’,’_self’,’’);

Posted in JavaScript | Leave a comment