Thursday 22 March 2012

ASP DataPager double click to move page

I have only just got around to using the .NET 4.0 DataPager control, and whilst impressed at the simplicity of setting it up, I was annoyed with two features:

1) You have to bind it to a ListView, it does not work with a Repeater control which is a little strange as exactly what I was achieving in the repeater I can do with no code change to get it to work in the ListView
2) When you want to page, say from page 1 to page 2 of the results, you have to double click the "next" button twice to move forward.

Nothing I can do about 1) above, but as for 2), just ensure that the listview it is being re-bound during the pagination by adding the OnPagePropertiesChanged attribute to the ListViews markup, e.g:

OnPagePropertiesChanged="lstSearchResult_OnPagePropertiesChanged"

and in the code behind, bind on the event

protected void lstSearchResult_OnPagePropertiesChanged(object sender, EventArgs e)
{
     lstSearchResult.DataBind();
}

Tuesday 13 March 2012

Jquery ajax call to WCF stops working when upgrading to jquery 1.7.1

This had me puzzled for ages. When upgrading the version of jquery we use from 1.5 to 1.7.1 so that we could use Bootstrap popovers, any calls to our WCF .NET service would fail with a blank error message returned.


What I found was that within out Ajax call we had set:


jsonp: "callback", dataType: "json"

In 1.5 this worked fine, however in 1.7.1 it had noticed that the response type was supposed to be jsonp (JSON with padding) and thus bombing out with a mismatch.


Changing this to the correct format of:


jsonp: "callback", dataType: "jsonp" 

Fixed the problem.