Saturday, March 24, 2012

DropDownList inside UpdatePanel not posting back

I have a DropDownList inside a UpdatePanel (inside a user control) declared like so:  
<asp:UpdatePanelID="UpdatePanel_DropDownList_Accounts"runat="server"> <ContentTemplate> <asp:DropDownListID="DropDownList_Accounts"runat="server"AutoPostBack="true" OnSelectedIndexChanged="DropDownList_Accounts_SelectedIndexChanged"> </asp:DropDownList> </ContentTemplate></asp:UpdatePanel>

The user control is rendered in a Sharepoint (WSS 3.0) page. The first time I select an item from the list,

a postback occurs and the event handler is called. Every time after that, however, there is no postback.

I believe the problem to be related to the UpdatePanel control as the DropDownList behaves as expected

(posting back to the server every time a new item is selected) when not embedded in an UpdatePanel.

Any help or suggestions anyone could offer me to solve this problem would be appreciated.

Hello Seedstorm,

I think you have to register the DropDownlist to do a Postback in the Page_Init of your Control. There you have to find the ScriptManager of the page that holds the control and do the registration like that (pseudocode)

protected void Page_Init() {

(Parent.FindControl("myScriptMgr") as ScriptManager).RegisterPostBackControl( myDropDownCtrl );

}

I hope this helps you!


Hi CodeGod,

Thank you for replying. I did as you suggested. I registered the DropDownList using both the RegisterPostBackControl and RegisterAsyncPostBackControl methods.

After registering the control using RegisterPostBackControl, on the first change of the SelectedIndex of the DropDownList, the page performed a postback; on the second time, the UpdatePanel performed a partial-page update with the same net result that some form of postback occurred and the event handler was called. After that, however, any further changes of the SelectedIndex did not produce a postback.

After registering the control using RegisterAsyncPostBackControl the behavior was the same as I described in the first post.

Thanks again for taking the time to help; if you have any other suggestions, please let me know.


change or Set the UpdateMode = "Conditional" or "Always" for UpdatePanel

See the results it its' satisfying your requirments.


Thanks to both of you for helping. I've resolved the issue; it had to do with a custom wrapper Sharepoint places around the form when submitting that interferes with the behavior of the UpdatePanel. The solution I found was written up in a Blog post by Mike Ammerlaan:

http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3

No comments:

Post a Comment