开发者

What is the recommended way to do bind data to a <select> using ASP.NET, Knockout.js, JQuery? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 9 years ago.

Improve this question

The applications I work on are all ASP.NET apps for 开发者_运维知识库an intranet website. We are adding more and more JQuery client side code to the apps to enhance the user experience. The dropdownbox filling however is still done on a codebehind page like described in 1.

What is the best way to do it "nowadays":

  1. using ASP.NET serverside controls Using an asp:DropDownList doing a Databind on the server to initially populate the list

  2. doing an JQuery AJAX call getting the data as a List<> from a ASP.NET webservice and using Jquery to create options for each returned list item.

  3. Using a ViewModel use a webservice like in 2. but fill the result to knockouts viewmodel and use its data-binding capabilities to let knockout populate the select options.

Thanks!


Much of what you will want to do is going to depend on how you are posting data back to the server. As others have suggested, for large lists, using your option #2 or #3 is the way to go. However, by doing it this way, your DOM elements will not be added to the page ViewState and you will run into problems when posting back to the page. Your dropdown list selected value will be lost on postback. If you are going to use AJAX to post form data to the server and the page will not be performing a full postback then you'll be good to go as no page objects will be redrawn.

Using AJAX to populate your pages will give you a lot of control over the user experience as you'll be able to load large lists after the page has loaded. Your pages can become much more dynamic and your users will appreciate this. In our company, we work with large lists of data and sending everything to the page in one shot would not work. Moreover, we have users access pages from around the world and speed of page load is definitely an issue. AJAX/JSON has allowed our pages to load much quicker for all users. We do everything client-side and we only post data back to the server using AJAX so we never run into problems posting back.

Go with what you know. However, it is definitely worth your while to run some AJAX tests and see how comfortable you and your colleagues are with this new approach.


Generally when working with a given platform I like to think that it is best to do as much as possible with the platform itself and then use other languages such as Javascript to enhance the features of the site. When you start separating out different responsibilities to all the different pieces being used on your site it makes the overall architecture convoluted.

Having worked with a number of other web developers I don't think there really is a single way to do it these days. It all depends on how clear you want the architecture of your site to be and personal preference.

That being said I think the best practice for you would be to mimic what has been done already. If responsibility for updating and maintaining data has already been delegated to jQuery, then use jQuery to populate/update. If it has not, then stick with using ASP.NET to its fullest potential and jQuery only to make things smoother. A good middle ground between these two would be to use jQuery.ajax and call an asp.net web method for pushing/pulling data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜