ASP.NET DropDownList AutoPostback not working - what am I missing?

I am trying to get a DropDownList for AutoPostBack via UpdatePanel when the selected item is changed. I am a little embarrassed why this is not working.

Does anyone have any quick ideas?

ASPX page:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true" > <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>item 1</asp:ListItem> <asp:ListItem>item 2</asp:ListItem> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> 

Code-behind (I set a breakpoint on the line assignment to capture the postback):

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string s = ""; } 

Edit:

OK, now I'm working. Very strange. All that is needed is a reboot of Visual Studio. This is what scares me as a developer;) I think I’ve seen something like this before where VS is “out of sync” with the build.

FYI I am running VS 2008 Web Developer Express.

Thanks to those who answered.

+3
source share
5 answers

I was able to get it to work with what you posted. This is the code I used ... Basically what you had, but I threw an exception.

  <asp:ScriptManager ID="smMain" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true" > <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>item 1</asp:ListItem> <asp:ListItem>item 2</asp:ListItem> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { throw new NotImplementedException(); } 

I tried many options to see if there is something, but an exception was thrown every time.

You might want to try the exception route to see if postback occurs, and this is not a debugger problem.

  • One of the problems might be with Vista and not starting Visual Studios as an administrator. I know that I tend to prevent debugging.

  • Perhaps the assembly you are using does not match the code? This can happen if you are "View in Browswer" and then attach the debugger.

+5
source

Does this work when you take out the UpdatePanel?

+1
source

EnableViewState = "true" in UpdatePannel will solve the problem.

+1
source

I also had the same problems, oddly enough, my updated panel launched OnTextChanged in FireFox, but was dead in IE. Restartin VS 2005 fixed the problem .: About

0
source

Instead of using AutoPostBack = "true" set DropList as a trigger in the update panel.

-one
source

All Articles