B
bogdan
I need to pass a dropdownlist's selected value from one page to another. I
thought that handling DataBound() and SelectedIndexChanged() events of the
dropdownlist is all I needed to do in order to 'capture' the currently
selected value - the former handler would 'capture' the initial value and
the latter one would deal with any selection changes due to user UI on the
client side. Well, this approach worked in some cases only. I found out
that the only reliable way to 'capture' the selected value is to get it in
Page_Load() if IsPostBack instead of SelectedIndexChanged(). So, the
working solution in this case seems to be a combination of DataBound() and
Page_Load() (only if IsPostBack). If this is the case then why would anyone
use SelectedIndexChanged()?
A simple example to illustrate the problem with a dropdownlist containing
Item0...Item4:
1) On PageA select Item2 and move to PageB, handle OnSelectedIndex() and
pass selected value in a query string
2) On PageB press browser's back button to get back to PageA (note that
Item2 is appears selected in the list), proceed as in step 1) but select
Item0
Note that SelectedIndexChanged() will not execute when you post back PageA
in step 2). As a result your query will end up with Item2's value.
Am I missing something obvious?
Thanks,
Bogdan
thought that handling DataBound() and SelectedIndexChanged() events of the
dropdownlist is all I needed to do in order to 'capture' the currently
selected value - the former handler would 'capture' the initial value and
the latter one would deal with any selection changes due to user UI on the
client side. Well, this approach worked in some cases only. I found out
that the only reliable way to 'capture' the selected value is to get it in
Page_Load() if IsPostBack instead of SelectedIndexChanged(). So, the
working solution in this case seems to be a combination of DataBound() and
Page_Load() (only if IsPostBack). If this is the case then why would anyone
use SelectedIndexChanged()?
A simple example to illustrate the problem with a dropdownlist containing
Item0...Item4:
1) On PageA select Item2 and move to PageB, handle OnSelectedIndex() and
pass selected value in a query string
2) On PageB press browser's back button to get back to PageA (note that
Item2 is appears selected in the list), proceed as in step 1) but select
Item0
Note that SelectedIndexChanged() will not execute when you post back PageA
in step 2). As a result your query will end up with Item2's value.
Am I missing something obvious?
Thanks,
Bogdan