views:

615

answers:

3

I am completely stumped on this and would really appreciate any help.

I am working on a user control that is situated inside of an update panel. There is a button on the form which loads some data. This is working correctly.

There is also a drop-down box to filter the data. Changing this does initiate a post back, however nothing happens. The drop-down box goes back to it's default value the OnSelectedIndexChanged function is never called.

I've put break points in page_prerender and page_preload and both are being hit the post back is definitely occuring. Breakpoints withing the dropdownGroup_changed function are never hit.

Removing the update panel solves the problem, however it breaks the rest of the page so I can't use that for anything other than testing.

I've also verified that there is nothing in my prerender / page load that is resetting the page's state.

Here is the update panel code:

<asp:UpdatePanel ID="UpdatePanel6" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >    
<ContentTemplate>   
    <ucControlName:ControlName ID="ControlName1" runat="server" />   
</ContentTemplate>
</asp:UpdatePanel>

Here is the drop-down in question - It is located inside of the user control

<asp:DropDownList ID="dropdownGroup" runat="server" Visible="false" AutoPostBack="true" OnSelectedIndexChanged="dropdownGroup_changed"></asp:DropDownList>

It is of course visible and databound by the point in the code where the issue is occuring


A bit more info- added Both a hard coded dropdown (To rule out a stupid databinding issue) and a textbox to the same control. I have the same issue.

It appears that the event isn't triggering because the values are never changing as far as .net is concerned. I've checked the control during page_init and page_load - the value is always the same.

The fact that the button works but the other controls don't makes me think that there is a view state issue here somewhere but I can't quite ferret out what is causing it. Viewstate is enabled for the page and the panel- don't know if anything else could be overriding / corrupting it.

Did i mention that I hate update panels with a passion? because I hate update panels with a passion.

+1  A: 

Two answers for the price of one:

  1. Are you calling DataBind() in your Page_Load? If you do that on a PostBack, you will lose events. Replace the call with the following:

    if (!IsPostBack) { DataBind(); }

  2. If your DropDownList is outside your UpdatePanel, you need to add a Trigger as follows:

<asp:UpdatePanel ID="UpdatePanel6" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >    
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="dropdownGroup" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>   
    <ucControlName:ControlName ID="ControlName1" runat="server" />   
</ContentTemplate>
</asp:UpdatePanel>
John Christensen
Thank you very much for the quick response. The drop-down list is inside of the control which is inside of the update panel. I double checked and the data binding is not occurring within page load or page preload. Everything is within a !IsPostBack and the data-binding function actually occurs on a button press elsewhere in the form.
apocalypse9
Is the dropdownGroup_changed defined within your user control, or on your page?
John Christensen
It is within my userControl - marked as protected.
apocalypse9
A: 

I suggest checking the 'Value' property for each 'ListItem' in the 'DropDownList' control. If they are all the same even if the 'Text' properties are different, then the 'OnSelectedIndexChanged' will not fire at all since ASP.NET cannot tell if anything has changed (See this related question for more info.)

This was the real cause of my problem even though I, too, had a 'UserControl' with a 'DropDownList' inside an 'UpdatePanel' and the 'AutoPostBack' was firing as expected. I thought the UpdatePanel was the culprit but it was not the case. Each of the items in my DropDownList had the same underlying value of "10" even though they had distinct 'Text' values. I changed them to each have a unique value which then allowed for the OnSelectedIndexChanged event to fire thus fixing the problem.

Ray Vega
I was really hoping this was it- Unfortunately the underlying values are all distinct so it doesn't appear to be the culprit. While the bound values are all different the value always reverts to the default during the postback. I also tested with a text box just in case and it appears to have the same issue. Thank you again- I appreciate all the ideas I can get right now.
apocalypse9
@apocalype9- Sorry to hear this did not help either.
Ray Vega
A: 

Have you tried UpdatePanel.Update (); after your databind.

Ved