Search code examples
c#asp.netautopostback

Asp.net autopostback


Is there a way to add items to a dropdownlist (or any other control with lists) and when SelectedIndexChange happens, it doesn't keep adding all the items everytime that event happens? I suppose one way would be to clear the list before the add code but is there another?


Solution

  • It looks like you are adding items to the list on Page_Load event. If you are doing that, in that case when ever SelectedIndexChanged occurs it will add the items again. You can check if its a PostBack don't add items.

    if(!Page.IsPostBack) // First time only 
     {
      //Add items to list
     }