Dynamic dropdowns enable without post back
-
I have dymanuc drop down generated controls ( in some cases I can have as many as 5,3.... or none). If I have 3 drop downs then first needs to be enable and after they select 1 second and so on. How would I do this witout post back? Currently I am adding AddHandler ddlGroupStudentTypes.SelectedIndexChanged, AddressOf ddlGroupStudentTypesValueChanged
-
I have dymanuc drop down generated controls ( in some cases I can have as many as 5,3.... or none). If I have 3 drop downs then first needs to be enable and after they select 1 second and so on. How would I do this witout post back? Currently I am adding AddHandler ddlGroupStudentTypes.SelectedIndexChanged, AddressOf ddlGroupStudentTypesValueChanged
If your dropdowns are truly dynamic, then you are going to have to make a request from the server to get the next dropdown's values. In the most technical sense, that is a post to the server. I assume that you mean that you don't want to do a page refreshing style of a postback. In other words, you want an ajax call to load the data for the next dropdown. You have two general schools of thought you can go with: 1. UpdatePanel. This lets you run things through your server side events, and it disguises the postbacks so they don't make the page refresh. Pros are that it is simpler to implement. You basically can implement it as you would if you wanted the dropdowns to do a postback to load the next one. Then you wrap the dropdowns in an update panel, and set a few things and you are done. The update panel makes all those postbacks become ajax calls that don't refresh the page. Cons are that it is far less efficient in terms of bandwidth and server resources, and it can lead to some difficult debugging if you aren't familiar with the .net life cycle. Update panels result in a massive amount of auto generated javascript and additional markup being rendered to the browser which is not really ideal. Also, update panels only work for web forms applications, and are not available for MVC. I assume from what I saw in your question that you are doing web forms. 2. Ajax calls to web methods. Pros are that this is clean and efficient. You save tons on bandwidth consumption which can be a big deal for slow connection users. You also take a much lighter load on the server resources, which is a big deal for higher traffic solutions. You also are in much better control of what is rendered to the browser. Cons are that you have to know javascript a lot better than you would with update panels, and you have to take care of a few specifics that update panels abstract or take care of for you. I vastly prefer the 2nd option. If you go with the ajax option, then I can give you some additional pointers and things to look out for. I would suggest you use jquery and set up something like: in javascript: $("#myDropDown1Id").change(function(){ $.ajax({...//look at jquery.com for your specifics. You set your address, and send your parameters success:function(data){ //receive the data from your server and populate dropdown2 }, error:function(data){ //notify the user in some way });//end of .ajax });//end of change function Then you need to have a function exposed to be called as a web ser