我正在尝试在更改所选项目时通过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。
感谢那些回答。
答案 0 :(得分:5)
我能够让它与您发布的内容一起使用。这是我使用的代码...基本上你有什么,但我抛出异常。
<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。我知道有一种不允许调试的倾向。
您运行的程序集可能与代码不匹配?如果您“在Browswer中查看”然后附加调试器,则可能会发生这种情况。
答案 1 :(得分:1)
取出UpdatePanel时是否有效?
答案 2 :(得分:1)
UpdatePanel中的EnableViewState =“true”肯定会解决问题。
答案 3 :(得分:0)
我也遇到了同样的问题,奇怪的是我的updatepanel在FireFox中解雇了OnTextChanged但在IE上已经死了。 Restartin VS 2005解决了这个问题。 :o
答案 4 :(得分:-1)
而不是使用AutoPostBack =“true”而不是将DropList设置为更新面板中的触发器。