开发者

Event issue with ASP.net Update Panel

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.


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.


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>
    


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜