问题描述
我在UpdatePanel中有一个页面,其中包含一个Repeater,其中包含服务器控件元素,而所有其他控件的行为均正常,但Drop Down控件每次都会引起完整的回发。
I have a page that contains a Repeater, which contains server control elements, within an UpdatePanel and while all other controls behave normally, the Drop Down control causes a full postback every time.
<asp:Repeater ID="rpt" runat="server">
<ItemTemplate>
<asp:SomeWorkingControl ID="swc" runat="server" />
<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="0" Value="0" />
<asp:ListItem Text="1" Value="1" />
</asp:DropDownList>
</ItemTemplate>
</asp:Repeater>
这是我的代码的样子,DropDownList控件实际上在UserControl中,但是理论上一样。
This is vaugely what my code looks like, the DropDownList control is actually in a UserControl, but the theory is the same.
如果我将事件应用于SomeWorkingControl,则存在Ajax回发,一切都很好。
If I apply an event to SomeWorkingControl then there is an Ajax postback and all is fine.
但是,与DropDownList关联的事件导致完整的回发!我知道通常您会为DropDown设置一个异步触发器,但是由于它是在转发器中创建的(因此我不知道会有多少个触发器),所以我真的不知道它如何工作。
However, the event associated with the DropDownList causes a full postback! I know usually you would set an Async trigger for the DropDown, but since it is created in a repeater (and therefore I can not know how many there will be) so I don't really see how that could work.
有没有人曾经经历过这种情况并且可能知道解决方法?
Is there anybody who has experienced this before and knows a workaround perhaps?
推荐答案
尝试更改此行:
<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true">
用于:
<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true" ClientIDMode="AutoID">
最近我遇到了同样的问题,发现ClientIDMode可以解决它。
Recently I had the same problem and I found out that the ClientIDMode can solve it.
请在此处查看:
这篇关于ASP.NET C#,转发器中的动态下拉列表导致完整的回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!