views:

6748

answers:

4

I am attempting to get a DropDownList to AutoPostBack via an UpdatePanel when the selected item is changed. I'm going a little stir-crazy as to why this isn't 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 put a breakpoint on the string assignment to capture the postback):

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

Edit:

OK, I have it working now. Very weird. All it took was a restart of Visual Studio. This is the kind of thing that frightens me as a developer ;) I think I've seen similar before, where VS gets "out of sync" wrt the assembly it's running.

FYI I am running VS 2008 Web Developer Express.

Thanks to those that answered.

+1  A: 

Does it work when you take out the UpdatePanel?

spaetzel
thanks - just tried it. still doesn't work! I'm going to create new page from scratch and try an autopostback.
Ben Aston
+2  A: 

I was able to get it to work with what you posted. This is the code I used... Basically what you had but I am throwing 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 a lot of variations to see if there was something off, but the exception was thrown every time.

You might want to try the exception route to see if the postback is happening and this isn't a debugger issue.

  • One issue might be with Vista and not running Visual Studios as administrator. I know that has a tendency to not allow debugging.

  • Maybe the assembly you are running doesn't match the code? This might happen if you "View in Browswer" and then attach the debugger.

Programmin Tool
hey thanks man - I'll try your code and let you know how i get on
Ben Aston
OK, I have it working now. Very weird. All it took was a restart of Visual Studio. This is the kind of thing that frightens me as a developer ;) I think I've seen similar before, where VS gets "out of sync" wrt the assembly it's running. Thanks!
Ben Aston
Oh yeah, forgot about that one. Had that happen a lot really.
Programmin Tool
A: 

I too had the same issues,strangely enough my updatepanel was firing OnTextChanged in FireFox but was dead on IE. Restartin VS 2005 fixed the issue. :O

A: 

Rather than using AutoPostBack="true" set the DropList as a trigger in the update panel.