开发者

Are there any ASP.NET template technologies which can be used both client and server-side?

开发者 https://www.devze.com 2023-01-08 07:48 出处:网络
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.

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 contr开发者_开发问答ols 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.


HAML


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消