What I’m trying to do:
Create a ‘grid’ once the page loads with some settings, then rather than using post backs to regenerate this grid I want to use nice quick service methods, i.e. page change, filter results
What I’d usually do is re-create the html based on a DTO that the service passed back. Now the issue I have is that I’m in effect creating the Html in two places (in the asp.net page) and also in the JavaScript.
Now I know this could be done by using MVC in the same application, creating a partial, rendering it on the server and sending back the Html (After adding the model to it).. But it seems a bit hacky
Alternatively I could create the html in the code behind, but that seems a bit crap, would be great to have it in a html like editor.. again like a partial..
Am I missing something really obvious, is there a cleaner way? (Still using ASP.net)
I would suggest looking at the possibilities offered by Allan Jardine’s excellent jQuery plugin DataTables. I’ve been using it for a couple years and it has proven itself many times over as being fast, very cross-browser friendly, and integrates reasonably well with 2D arrays coming back from an ASMX webservice, or my preferred method, List<MyObject>, which ASMX serializes as an array of JSON objects.
Much of the time we don’t even need to worry about paging server side. If you’re handling less than a couple thousand rows of data, dataTables is plenty fast to handle paging and filtering of that data all on the client, even in older browsers. IE6/7 start to get a bit jerky sometimes, but remain what I would consider, usable.