Asp.Net — adding option to select on client side…no value in code behind on form submit

StackOverflow https://stackoverflow.com/questions/204963

  •  03-07-2019
  •  | 
  •  

Question

I'm quite confused by something. I've got 2 select lists, and if you choose an option in the first, I then load the 2nd with a certain set of options. I clear this out and repopulate it every time you change the selection in the first select element. Now, on postback, I need to know the value of the option that was selected in the 2nd select element, but it is always showing up as -1.

I'm sure I'm missing something fundamental and dumb on my part, but can anyone point me in the right direction?

Was it helpful?

Solution

I don't actually see the code, but what is probably happening is that you are clearing it before actually looking at the value, probably in your Page_Load.

OTHER TIPS

Did you say you were adding items to the right hand list using client side code rather than server side code?

If so you will need to capture the form items being posted manually (Request.Form) and populate the listitem with these new details. Or at least that is what I remember off the top of my head.

If you post some more details about if it is a server side or client side addition to the listbox I'm sure someone with a bit more time can give you the answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top