ASP.NET Error Message: Invalid postback or callback argument

If you're trying to create a post-back from Javascript in ASP.NET, you might have come across the following error:

Invalid postback or callback argument. Event validation is enabled using in configuration or in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

This message is caused because ASP is attempting to validate that a given post-back that was initiated from Javascript is really supposed to be happening; basically, it is an attempt to try to prevent cross-site scripting from issuing post-backs. You can do as the message says and register the callback, you can edit your web.config file, or you can do what I do, and add the following line to your Page directive in your .aspx page like so:

<%@ Page EnableEventValidation="false" ... %>

Be aware that by setting EnableEventValidation to false, you're opening a hole in your security. I'm using this in a situation where the risk has been minimized, but if you're including external scripts, you might want to actually go through the trouble of registering the event.

 

Using Event Bubbling to Your Advantage

Its happened to everyone working with Javascript: you build your test app that handles clicks on elements to do really neat things and everything's going great. You move it live, and as the data starts coming in your app gets slower and slower until finally the system starts to become unusable. Whats the problem? In testing you had maybe five or ten clickables, but your app has been growing, and you've now got 20, 60, 120 or more, and the time it takes to bind all of your click events is skyrocketing. What if you could just use a single handler for all of them?

 

Preventing Multiple Submissions with Prototype and jQuery

If there is one problem that plagues me across applications, its users that are too antsy to wait for the page to come back after hitting submit on a form. Even worse, some people just instinctually double and triple click. How do you keep these pesky users from duplicating records or charging themselves three times for that item in your e-shop? Click "more" to see how I do it in Prototype and jQuery.

 

Javascript Gerundization

Ever needed to "gerudize" a word? No? I needed to today to convert links and button labels like "Save" and "Submit" into their gerund equivalents: "Saving" and "Submitting". I found a set of rules on how to convert a verb into a noun here, and put together a simple Javascript implementation. I might do a ColdFusion one later to match my Pluralize() and Singularize() utility functions.

function gerundize (word) {
    if ( word.match( /[^aeiou]e$/i ) ) {
        word = word.slice(0, word.length-1);
    } else if ( word.match( /[^aeiou][aeiou][^aeiou]$/i ) ) {
        word = word + word.slice(word.length-1, word.length);
    }

    return word + 'ing';
}

And the test code:

document.write(gerundize('Think'));
document.write('<br />');
document.write(gerundize('Submit'));
document.write('<br />');
document.write(gerundize('Hit'));
document.write('<br />');
document.write(gerundize('Take'));
document.write('<br />');
document.write(gerundize('Create'));
document.write('<br />');
document.write(gerundize('Save'));
document.write('<br />');

 

Escaping Console.log()

Firebug icon Ray Camden just Twittered about checking in code that still has console.log() in the Javascript. He rightly points out that console.log() causes problems for browsers that don't understand it, but you don't really have to have Firebug installed as some browsers like Chrome understand it natively. Rather than try to purge my code of console.log(), and need them again later, my solution is to add an "escape" that lets console.log() evaluate harmlessly on browsers that don't support it. Click more to see the code.

 

Wild Friday Night with Javascript Controllers

Javascript code All because of Ben Nadel, I'm writing Javascript examples instead of playing Fallout 3 tonight... Ok, so in my post evolution of a js controller scheme, Ben commented that he wasn't comfortable with the idea that the this value inside my controller was the window object, rather than the controller itself. So, I've set out to see if I can rework the controller to use "new" and grow up to be a real object. Read more to see how I do.

 

More Entries

Post a job. Find one. authenticjobs.com