Archive for the ‘JavaScript’ Category

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

Thursday, August 6th, 2009

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 code behind via Request.QueryString.

To avoid ending up with “unkown” characters in your resultant string, use the JavaScript function “encodeURIComponent()” instead.  This should correctly encode your URLs for UTF-8.

 

 

Sys.WebForms.PageRequestManagerServerErrorException in FireFox with MSFT Ajax

Thursday, December 11th, 2008

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 = e.get_error();
if (err) {
if (err.name == "Sys.WebForms.PageRequestManagerServerErrorException") {
e.set_errorHandled(true);
}
}
}

Hope it works for you!


Using the PageRequestManager in ASP.Net AJAX (ATLAS)

Thursday, September 27th, 2007

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 + ', ';
}

for(var i=0;i
u += args.get_panelsUpdated()[i].id + ', ';
}

alert(c);
alert(u);
}

FireFox caches JavaScript state

Thursday, September 27th, 2007

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(); // No client side cashing for non IE browsers
}



Automatically close a window in FireFox

Thursday, September 27th, 2007

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’,’’);