Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

c# - ASP.NET DropDownList AutoPostback Not Working - What Am I Missing?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...