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”:
-
using ASP.NET serverside controls
Using an asp:DropDownList doing a Databind on the server to initially populate the list -
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. -
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.