Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a dropdown which has a selectedIndexchanged event which fires on first postback(a button click) and it stops firing for the next postbacks.

XML
<asp:DropDownList ID="AreaDD" Width="150px" AutoPostBack="True" runat="server" OnSelectedIndexChanged="AreaDD_SelectedIndexChanged">
                                </asp:DropDownList>



Why it is firing for button click event?


Thanks in Advance
Posted
Updated 27-May-14 0:59am
v2
Comments
Bh@gyesh 27-May-14 7:00am    
SelectedIndexChanged event fires only when you change item in dropdownlist. It will not fire on initial formload postback.

Have you explicitly call this event in page_load event?
idhris2011 27-May-14 7:18am    
No, the event was not explicitly called anywhere. When I click the button, the selectedIndex event was called and the it comes to the button click event and when I click the button again, it directly comes to the button click event and selectedIndex was not called.
Bh@gyesh 27-May-14 7:24am    
Ideally, when u click on button the selectedindexchanged event must not be called. IT should called only when you change selected items from dropdown.
Can you share your code here?
Bh@gyesh 27-May-14 7:31am    
Add property - EnableViewState = True in dropdownlist.
idhris2011 27-May-14 7:38am    
It works same even setting EnableViewState = True, if False then I am losing the values in dropdown

1. Your ASP.NET code will generate postback each time you select a new item in the list, and it will not generate any postback if you do not select other item (or your item list has only one item and this item was already selected).

2. If you want that the event to be fired only when you click on submit button from your page, and the current index was changed before to press on button, you have to change the property AutoPostBack to false.
 
Share this answer
 
v2
on selectedindexchangedevent... at End Of Event set the property AreaDD.AutoPostBack=false; in .cs file.
C#
protected void timezone_SelectedIndexChanged(object sender, EventArgs e)
      {


/// Add your Code for first index change /////////////



          timezone.AutoPostBack = false;

      }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900