Hi,
I am looking for assistance on how to correctly post events when a new item is selected on a drop down list.
My drop down list has autopostback enabled and a sub routine associated with SelectedIndexChanged. This routine is activated when another entry in the drop down list is selected, however, the value is not changed and the drop down list returns to the originally selected value.
For example, if I have 2 values in my drop down list, 0 and 1, and 0 is the currently selected value. Selecting 1 will trigger the event but the drop down list will return to displaying 0 as the selected value. Even looking at DropDownList.Text in debugger the value is not changing from 0 to 1.
By turning off AutoPostBack the event is not triggered.
Can anybody give advice on what I need to do to correctly trigger an event when the value of a drop down list is changed?
Thanks.
![]() |
0 |
![]() |
Sounds like your initial Data binding method(s) are getting called again. Are you using the IsPostBack check before calling those methods?
If IsPostBack = false then
BindData
End If
Chris Love
ASP.NET 2.0 Your Visual Blueprint for developing Web Applications
![]() |
1 |
![]() |
where do you populate your DDL?
Regards,Vinz
"Code, Beer and Music" that's my way of being a programmer!
How to get your Forum Question Answered | Blog | CodeASP.NET
![]() |
0 |
![]() |
I wasn't using IsPostBack, should I be?
Drop Down List has fixed values set using the Edit Items option, but the selected value, when the applicationis running, is determined by a stored proc call. One of the available values in the drop down will be returned from the DB table.
When the value is changed I'm hoping to use the event to alter the value of another textbox (or field).
If I'm being too vague here let me know. I can post more details it necessary.
Thanks for the help.
![]() |
0 |
![]() |
can you show us the code?
Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
Regards,
Pedro Abraham de la Cruz
![]() |
0 |
![]() |
There's not much to it really.
Early I set the value selected in the DDL by using
myDropDownList.Text = ValueReturnedFromStoredProc
This is the event handler
Protected Sub myDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myDropDownList.SelectedIndexChangedfunctionThatDoesMoreStuff()
End SubThe function I call attempts to use the value in myDropDownList.Text but there is no change to the value of myDropDownList.Text so nothing really happens. And the DDL reverts to the value it was set to before a new value was selected.
The DDL has AutoPostBack set to True, and SelectedIndexChanged Action calls myDropDownList_SelectedIndexChanged. This call works, it's the value not changing that has me stumped. If I turn off AutoPostBack the value changes but the event handler is not activated.
![]() |
0 |
![]() |
clum:
There's not much to it really.
Early I set the value selected in the DDL by using
myDropDownList.Text = ValueReturnedFromStoredProc
This is the event handler
Protected Sub myDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myDropDownList.SelectedIndexChanged
functionThatDoesMoreStuff()
End Sub
The function I call attempts to use the value in myDropDownList.Text but there is no change to the value of myDropDownList.Text so nothing really happens. And the DDL reverts to the value it was set to before a new value was selected.
The DDL has AutoPostBack set to True, and SelectedIndexChanged Action calls myDropDownList_SelectedIndexChanged. This call works, it's the value not changing that has me stumped. If I turn off AutoPostBack the value changes but the event handler is not activated.
Hi clum,
Could you post the whole code here?
Waiting for your feedback,
Hong Gang
Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
Hi Hong Gang
I eventually figured this one out, it was Chris Love who pointed me in the right direction.
Fairly new to .Net and I didn't realise the Page_Load sub was being tirggered from the PostBack event. In Page_Load the value selected was overwritten, with the DDL being reset to it's original value.
I'm using IsPostBack to avoid this now.
Thanks everybody for your help. In hindsight I probably would have figured this out a lot earlier if I'd set a breakpoint for Debugger at a much earlier stage....
![]() |
0 |
![]() |