【问题标题】:ASP.NET DropDownList AutoPostback Not Working - What Am I Missing?ASP.NET DropDownList AutoPostback 不起作用 - 我错过了什么?
【发布时间】:2008-12-04 15:52:10
【问题描述】:

当所选项目发生更改时,我正在尝试通过 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。

感谢那些回答。

【问题讨论】:

    标签: c# asp.net updatepanel autopostback


    【解决方案1】:

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

       <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。我知道这倾向于不允许调试。

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

    【讨论】:

    • 嘿,谢谢伙计——我会试试你的代码,让你知道我的进展情况
    • 好的,我现在可以使用了。很奇怪。只需重新启动 Visual Studio。这是让我作为开发人员感到害怕的事情;)我想我以前见过类似的情况,VS 在它运行的程序集中“不同步”。谢谢!
    • 哦,是的,忘了那个。真的发生过很多次。
    【解决方案2】:

    UpdatePanel 中的EnableViewState="true" 肯定能解决问题。

    【讨论】:

      【解决方案3】:

      我也遇到了同样的问题,奇怪的是,我的更新面板在 FireFox 中触发了 OnTextChanged,但在 IE 上却死了。 Restartin VS 2005 解决了这个问题。 :O

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 2020-09-14
          • 1970-01-01
          • 2020-08-26
          • 2022-01-21
          • 1970-01-01
          • 1970-01-01
          • 2017-03-23
          • 1970-01-01
          • 2018-04-30
          相关资源
          最近更新 更多