ASP.net Update Panel Event

I am completely fixated on this and will be very grateful for any help.

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

There is also a drop-down list for filtering data. Changing this triggers the message back, but nothing happens. The default value is returned from the drop-down list; the OnSelectedIndexChanged function is never called.

I set breakpoints in page_prerender and page_preload, and both of them fall back into the message, definitely happening. Breakpoints with the dropdownGroup_changed function never hit.

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

I also confirmed that nothing happens in my prerender / page load, which causes the page to reset.

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 list - it is inside the user control

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

This, of course, is visible and tied to a point in the code where the problem occurs.


A bit more information. Added both a string encoded drop-down menu (to eliminate the stupid data binding problem) and a text field to the same control. I have the same problem.

It seems that the event does not fire because the values ​​never change in relation to .net. I checked the control during page_init and page_load - the value is always the same.

The fact that the button works, but other controls do not make me think that there is a problem with the presentation, but I can not understand what causes it. Viewstate is enabled for the page and panel - I don’t know if something else can override / corrupt.

Did I mention I hate update panels with passion? because I hate update panels with passion.

+4
source share
3 answers

Two answers for the price of one:

  • Are you calling DataBind() on your Page_Load ? If you do this on PostBack , you will lose events. Replace the call as follows:

     if (!IsPostBack) { DataBind(); } 
  • If your DropDownList is outside of your UpdatePanel , you need to add 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> 
+1
source

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 from each other, then “OnSelectedIndexChanged” does not work at all, since ASP.NET cannot determine if something has changed (see this related question for more information.)

This was the real cause of my problem, although I also had a “UserControl” with a “DropDownList” inside the “UpdatePanel”, and the “AutoPostBack” shot as expected. I thought UpdatePanel was the culprit, but it wasn’t. Each of the elements in my DropDownList had the same base value of 10, although they had different Text values. I changed them to each of them, it has a unique value, which then resolved the OnSelectedIndexChanged event, thereby eliminating the problem.

+1
source

Have you tried UpdatePanel.Update (); after your data binding.

0
source

All Articles