我有一个下拉列表,当我将AutoPostBack=设置为“真”时,页面会一直刷新。
谁知道可能出了什么问题?
<asp:Repeater ID="repFunctionsToAdd" runat="server" OnItemDataBound="repFunctionsToAdd_ItemDataBound">
<ItemTemplate>
<div class="person-section">
<div class="row">
<strong>
<%# Eval("Name") %>
</strong>
<a class="btn-question" href="#">question</a>
<div class="load">
<img src="../images/load<%# Eval("PreProductionLoad") %>.gif" width="40" height="16" alt="image description" />
<img src="../images/load<%# Eval("ProductionLoad") %>.gif" width="40" height="16" alt="image description" />
<img src="../images/load<%# Eval("PostProductionLoad") %>.gif" width="40" height="16" alt="image description" />
</div>
</div>
<div class="row">
<div class="btn01 btn-tilfoj">
<ctrl:Hyperlink ID="hlAddFunction" runat="server" Icon="Plus" Text="Tilføj" />
</div>
<label for="select2">
Tilføj til:</label>
<asp:DropDownList ID="ddlUsers" runat="server" Width="190" OnSelectedIndexChanged="ddlUsers_Sic" AutoPostBack="true" />
</div>
</div>
</ItemTemplate>
</Repeater>发布于 2010-09-20 16:34:46
DropDownList不应该在ItemTemplate中,因为这意味着它将对每个项目进行“重复”。
因为DropDownList将AutoPostBack设置为true,并且有一个静态事件处理程序,所以每当您选择一个项时,dropdown中的所有项都将触发autopostback事件。
因此,如果您的中继器中有100个项目,则对于每个选定的索引更改事件,AutoPostBack将触发100次。
讲得通?
将DropDownList移到中继器外部,它应该可以解决您的问题。
但是,如果您必须将其放在中继器中(如果希望每个项都有特定的行为),则需要在ItemCreated事件上连接SelectedIndexChanged事件:
protected void repFunctionsToAdd_ItemCreated(object sender, RepeaterItemEventArgs e)
{
DropDownList dll = e.Item.FindControl("ddlUsers");
ddl.SelectedIndexChange += ddlUsers_Sic;
}发布于 2010-09-20 17:43:14
如果您正在运行ASP.NET 2.0+配置,则可以将DropDownList放在UpdatePanel中,以防止整页回发。然后,这将只使用ASP.NET AJAX重新呈现页面的这一部分。
http://msdn.microsoft.com/en-us/library/bb386454.aspx
或者,您可以编写一个javascript脚本来运行WebMethod,它可以处理任何需要发生的服务器端更改。
https://stackoverflow.com/questions/3749759
复制相似问题