Feb 01 2007

Accessible Ajax calls 3 history and Ajax calls

Posted by admin under ASP.NET AJAX formally Atlas

Now in the downloadable solution look at default.aspx.

I have the next/prev  hyperlinks call the PostbackAndSetHistory js function which doesn't do much:



		    function PostbackAndSetHistory(controlid, controlvalue)
		    {
		        ASPCode.net.History.setLocation( controlid + '-' + controlvalue );
		        return false;
		    }


It will set the hash to a value based on the hidden field control id and the value (i.e the new page number). So for example

http://localhost:2166/default.aspx#rpt1_ctl00_CurrentPage-3   when looking at page 3.

However the setLocation will callback on us - lets look at that:



function OnLocationChanged(sender, args) 
{
	var controlid = result[0];
	var controlvalue = result[1];
	//1. Set control value
	//alert('Posting');
	$get(controlid).value = controlvalue;
	//2. Postback
	__doPostBack(controlid, '');

}

Please note that this is a heavily simplified version of the actual code(look yourself in the downloadable solution) cause in the real life things were not that simple. I even had to throw in a first flag and a stupid hardcoded reference to the control id since then moving in backwards in history we will finally get to the forst page (no hash at all) and that destroyed it all.

Anyway - I will try to work something out that's more easily used - however this is the first version and I hope it would be of help to some people at least..