Web - Posting Back On A SelectedIndexChanged

  • Thread starter Thread starter David P. Donahue
  • Start date Start date
D

David P. Donahue

I have a DropDownList that I would like to post back to the server when
the selected index changes. Using Visual Studio, I simply
double-clicked the DropDownList on the form and that created the
function call where I put my code, all well and good. But in practice,
changing the selection does not post back to the server and, thus, does
not run the code when I need it to be run. Is there a way to make this
happen?

I realize that conducting a postback on such an event isn't always the
best way to do things in the first place, but in this specific case on
this specific form it would pretty much be the best way to go. Any ideas?


Regards,
David P. Donahue
(e-mail address removed)
 
There's an autopostback property on the control that should be set to true
for this behaviour.

You're right though, that performing a postback isn't such a good way of
doing things because of the delay, but that said, for such an argument there
are always exceptions.

What are you doing with your server side code on the selection change?

Daniel.
 
There's an autopostback property on the control that should be set to true
for this behaviour.

Ah, I guess I missed that one. Works now, thanks :)
You're right though, that performing a postback isn't such a good way of
doing things because of the delay, but that said, for such an argument there
are always exceptions.

What are you doing with your server side code on the selection change?

To simplify the numbers: DropDownList A has 100 options. For each
option in A, DropDownList B has 100 options. Sending _all_ of B to the
client each time the page is loaded would slow things down a bit much.
Especially when you consider that 90% of the users will probably never
change the default selection in A (and, thus, never need to re-populate
B after the initial page load). So, when A changes, B gets populated by
"SELECT foo FROM bar WHERE something=A.Value"

Of course, if there is a better way to do this, I'm all ears. This just
seemed the simplest to implement without terribly sacrificing
performance for the user.


Regards,
David P. Donahue
(e-mail address removed)
 
In this case posting back is definately the way to go in my opinion. Sending
masses of data to the client is going to loose when put up against your
option of posting back with gradual amounts of data.
 
Back
Top