views:

57

answers:

2

Hi,

I have a dropdownlist, and when I set AutoPostBack="true", the page keeps refreshing.

any who knows what might be wrong?

<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>
+1  A: 

The DropDownList shouldn't be inside the ItemTemplate, as this means it will get "repeated" for each item.

Because the DropDownList has AutoPostBack to true, and one static event handler, every time you select an item, ALL of the items in the dropdown will fire the autopostback event.

So if you have 100 items in your repeater, the AutoPostBack will get fired 100 times for each selected index change event.

Make sense?

Move the DropDownList to outside the repeater, and it should solve your problem.

However, if you MUST have it inside the repeater (if want each item to have specific behaviour), you'll need to wire up the SelectedIndexChanged event on the ItemCreated event:

protected void repFunctionsToAdd_ItemCreated(object sender, RepeaterItemEventArgs e)
{
   DropDownList dll = e.Item.FindControl("ddlUsers");
   ddl.SelectedIndexChange += ddlUsers_Sic;
}
RPM1984
It makes sence, but it needs to be insite... there are some functions, that are repeated by the repeater, but each function, must have a list of users in a drop down.
Joshlo
@Joshlo - i though so. =) See my update
RPM1984
It keeps making postbacks when rendering the page
Joshlo
when RENDERING the page? you mean the first time? hmm, that's strange - what does the debugger tell you? What control is firing the postback?
RPM1984
it's the dropdown control that fires the postback, according to Request.Form["__EVENTTARGET"]
Joshlo
Even if I take it out of the repeater, it keeps firing the postback
Joshlo
@Joshlo - that's interesting (fact that even outside the repeater,it keeps firing postback). What's in your Page_Load event?
RPM1984
not sure what were wrong, so in stead, I removed the autopostback and gave it onItemCommand, and used a button to trigger it. but thx anyway :)
Joshlo
A: 

If you are running an ASP.NET 2.0+ configuration, you could put your DropDownList in an UpdatePanel to prevent full page post-back. This would then only re-render that segment of the page using ASP.NET AJAX.

http://msdn.microsoft.com/en-us/library/bb386454.aspx

Alternatively you could write a javascript script to run a WebMethod which could handle any server-side changes which need to occur.

Curt