开发者

Return HTML or data from the server - ASP.NET Webforms

I am working on a page that has multiple sections and each section looks 'almost the same'. Having said that, I want to build the HTML on the server and render it for each section on the initial page load. On subsequent actions, I would do a ajax call and have the server return json data.

The other option is to 'hardcode' the HTML on the aspx page and have the JS do the necessary customizations for each section. The third option is to use an UpdatePanel and do everything server side.

Based on what should I be choosing what approach to use? What approach would you use for a page like this (think of it as a large page having sub sections on it)

Edit: One section has HTML such as user's name, and a tab开发者_开发技巧le where users can add dependents. Another section is almost the same except its for a 'contractor' so there's additional HTML such as previous work history, but this one has name (readonly) and a table to add dependents just like the first one. Other sections have more or less the same HTML. A user can delete dependents as well, when that happens, I need to update the database and update the section to reflect one less dependent. I was hoping to make any subsequent actions as ajax calls that interact with the server and the database


In this situation I would make a control that used ajax calls to do its work. You could then have a few properties to set that would determine the minor differences between them. I'm also looking forward to another opinions/answers to this.

I would avoid the update panel at all costs it introduces a number of problems you won't have to deal with if you already understand JavaScript and ajax calls. You will also have much better performance without all the overhead included in the update panel.


Based on your update, it sounds like what you want is a custom control that would contain a bit of conditional logic to tweak the appearance based on its intended use. From there, use some ajax calls to communicate with the server when events such as adding/deleting dependents occur. So basically, what Mike said...


One option would be to create user controls for the "repeated" input fields, such as name and the grid for dependents.

Another option would be to use jQuery templates: http://plugins.jquery.com/project/jquerytemplate

I vote for not using an UpdatePanel for this :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜