Wednesday, June 2, 2010

Without Postback with disable your browser Javascript

Postback is very heavy code to load (viewstate,etc).
such as you want to get rid of this from your form .


So the solution is you can use AJAX.. to handle all this postback to make your page still dynamic or more responsive that before.

But how about if the client browser disable their javascript..
Your page will be static.

so you need to consider this as well.

So the big picture of this solution is to put ajax as common.
but on the event onclick or href.. you can't just call that function to call an ajax.

for example
href="javascript:CallPostbackFunction();"

you need to change this to
href="/page/ajax/somePage.aspx" class="AjaxCall"

then.. in you can check .. if the browser is enabled the javascript..
then you can call your ajax function.

If the javascript is disabled from your browser then you still can load to the proper page. instead of just do nothing.

//check if browser enabled their javascript
jQuery(document).ready(function() {
//perform init and replace to an proper javascript
var ajaxCalls = $('#ajaxCall');
ajaxCalls.unbind('click', this.addClick);
ajaxCalls.bind('click', this.addClick);
});


Here a good reference for Object Oriented Programming in Javascript
http://devedge-temp.mozilla.org/viewsource/2001/oop-javascript/

No comments: