ASP.NET DropDownList AutoPostback 不工作 - 我错过了什么?

发布于 2024-07-10 07:50:51 字数 1051 浏览 4 评论 0原文

当所选项目发生更改时,我试图通过 UpdatePanel 将 DropDownList 获取到 AutoPostBack。 我有点抓狂,为什么这不起作用。

有人有什么快速的想法吗?

ASPX 页面:

<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)
{
  string s = "";
} 

编辑:

好的,我现在可以使用它了。 很奇怪。 只需重新启动 Visual Studio 即可。 作为一个开发人员,这种事情让我感到害怕;)我想我以前也见过类似的情况,VS 与它正在运行的程序集“不同步”。

仅供参考,我正在运行 VS 2008 Web Developer Express。

感谢那些回答的人。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

过去的过去 2024-07-17 07:50:51

我能够让它与您发布的内容一起工作。 这是我使用的代码......基本上是你所拥有的,但我抛出了一个异常。

   <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();
    }

我尝试了很多变体来查看是否有问题,但每次都会抛出异常。

您可能想尝试异常路由以查看是否发生回发并且这不是调试器问题。

  • 其中一个问题可能是 Vista 和未以管理员身份运行 Visual Studios 引起的。 我知道这有不允许调试的趋势。

  • 也许您正在运行的程序集与代码不匹配? 如果您“在浏览器中查看”然后附加调试器,则可能会发生这种情况。

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.

时间你老了 2024-07-17 07:50:51

UpdatePannel 中的 EnableViewState="true" 肯定会解决该问题。

EnableViewState="true" in UpdatePannel will definitely resolve the problem.

故事与诗 2024-07-17 07:50:51

我也遇到了同样的问题,奇怪的是我的 updatepanel 在 FireFox 中触发 OnTextChanged 但在 IE 上死机。 重新启动 VS 2005 解决了该问题。 :哦

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

破晓 2024-07-17 07:50:51

不要使用 AutoPostBack="true" 将 DropList 设置为更新面板中的触发器。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文