ASP.NET C#, dynamic drop down in repeater causing full post back

旧时模样 提交于 2020-01-03 02:26:12

问题


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>

This is vaugely what my code looks like, the DropDownList control is actually in a UserControl, but the theory is the same.

If I apply an event to SomeWorkingControl then there is an Ajax postback and all is fine.

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?


回答1:


Try to change this line:

<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true">

for:

<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true" ClientIDMode="AutoID">

Recently I had the same problem and I found out that the ClientIDMode can solve it.

Please have a look here: asp.net ClientIDMode Changes



来源:https://stackoverflow.com/questions/18536656/asp-net-c-dynamic-drop-down-in-repeater-causing-full-post-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!