OutOFTouch
OutOFTouch

Reputation: 1077

DropDownList_OnSelectedIndexChanged event, In a UserControl is not firing on postback

I forgot to mention this asp.net 2.0.

The user control has a unique id and it is loaded in the PageLoad event. The user control is loaded into a panel and the panel is inside of a webpart. The dropdown has autopostback set to true.

EnableViewState = true on the dropdown. The ListItems are created in the dropdowns pre-render event method.

This is why I don't understand why it is not firing, the dropdown is the only thing that causes postback on this user control.

The event methods for the dropdown should occur since the user control is loaded in the page load method on postback again right?

Upvotes: 1

Views: 1877

Answers (2)

ronaldwidha
ronaldwidha

Reputation: 1345

Make sure there is no OnLoad or PageLoad event that is rebinding the datasource of the dropdown list. Rebinding the data with a new set of data may cause the clickhandler to not ever get executed.

make sure you have if (!Page.IsPostBack) around dropdownlist.datasource = and dropdownlist.databind()

Upvotes: 2

Asad
Asad

Reputation: 21928

I am not sure if this is your problem, but it is the most common.

Try with EnableViewState set to true for the DropDownList

If the ViewState is set to false, on post back the selected Index gets back to default which is normally the first Item. First item, if selected, does not cause SelectedIndexChange event to fire

Upvotes: 1

Related Questions