views:

76

answers:

2

Currently I'm working with ASP.NET 2.0, which may explain why I'm not as up on this as I might be. However, I don't see a full solution in my Googling of ASP.NET MVC, etc.

Here's my background thinking.

Firstly, data-bound templates are really useful. I'm currently dealing with lots of legacy code whereby people are building up controls programmatically, both on the client and the server, and it's a huge pain.

Secondly, sometimes you want controls to be data-bound on the client, sometimes on the server. The most obvious case for databinding on the server is where you're trying to account for people turning off javascript. But issues of speed, caching, bandwidth etc. all play their part as to deciding where to bind.

Now, on the server I can write UserControls with databinding points. And on the client I can write templates and bind them with JQuery (I'm currently using the microtemplating engine by John Resig as amended by Rick Strahl). But ideally there should be a way to write a template once and let the plumbing make it available for both server and client-side data binding. I guess that XML/XSLT would be one approach to this, but a horrible one. So what else is there? It needn't be an ASP.NET 2.0 solution; I'd just like to think that somewhere there is a fix.

A: 

You can create "datasource" objects that are independent of our databound controls / templates.

To use them with your databound control, instead of attaching them declaratively, e.g.:

<asp:gridview ...datasource="myDataSource"...>

you can attach them with code: (some event)

me.Gridview1.datasource = "myXMLDataSource"

---or---

me.Gridview1.datasource = "mySQLDataSource"

If you set the datasources up ahead of time (either in the .aspx or in the code-behind is OK), then in this way, you can switch datasources based on some event, or logic, when you want to, without having to re-code / re-publish anything.

dave
While this is all true, it's a little irrelevant. I was imagining some templating technology that works on both server and client.
Yellowfog
Your question is unclear. Reading it again...partly, it sounds like you want to be able to tell the datasource where to get it's data yourself at runtime, and partly, it sounds like you want the datasource to auto-detect when javascript is turned-off, and automatically switch to a server-side method for getting the data. What would this "template" look like, in your mind -- would you just tell it where the data lives, and then it would ask you what kind of datasource you wanted it to build for you? anyway -- some ideas in the following comments- maybe more in line with what you had in mind.
dave
http://www.codesmithtools.com/
dave
http://dotnetslackers.com/articles/ajax/ASPNETAjaxGridAndPager.aspx
dave
I'm sorry if I was unclear. More succinctly: I'm after a language-agnostic template markup plus both server-side (ASP.NET) and client-side (Javascript) libraries to bind datasets to the templates.
Yellowfog
Thanks -- If you're already familiar with ASP.NET, then you might be able to use CodeSmith without much trouble, as it has a similar style, and can integrate with Visual Studio as well. It can generate javascript as well as asp.net code (and even HAML :-)). Comes with lots of pre-built templates to get you started, and seems to have a pretty decent community to support your efforts. Good Luck.
dave
A: 

HAML

shawndumas
Template Tech: check.NET Server-Side Ver.: checkJS Client-Side Ver.: checkWhy the down-vote?
shawndumas
This is pretty interesting, thanks - I have no idea why you got downvoted. Definitely the right area.
Yellowfog