OnSelectedIndexChanged not firing on second change

Hi All,

I have a really weird issue with the OnSelectedIndexChanged functionality for the DropDownList

I have 2 values in the dropdown which change the layout of my results. When I change the selection from value 1 to value 2 it fires, but when I change it back to value 1 from value 2 nothing fires.

I'm begining to pull my hair out now!!

Thanks

Tom
<asp:DropDownList ID="viewBy" runat="server" OnSelectedIndexChanged="changedField_SelectedIndexChanged"
                            AutoPostBack="true">
                            <asp:ListItem Value="listView" Text="List"></asp:ListItem>
                            <asp:ListItem Value="thumbView" Text="Thumbnails"></asp:ListItem>
                        </asp:DropDownList>

Open in new window

LVL 1
TommyBoy1980Asked:
Who is Participating?
 
Alfred A.Commented:
Most ASP.NET Controls depend on ViewState a lot.

Check this out:   :-)

EnableViewState="False" -- the silent killer

http://weblogs.asp.net/dburke/archive/2004/05/13/130934.aspx
0
 
masterpassCommented:
Are you sure that the Value 2 retains in the dropdown as selected item when you select value 2

Try this
<asp:DropDownList ID="viewBy" runat="server" OnSelectedIndexChanged="changedField_SelectedIndexChanged"
                            AutoPostBack="true">
                            <asp:ListItem Value="listView" Text="List" Selected="True"></asp:ListItem>
                            <asp:ListItem Value="thumbView" Text="Thumbnails"></asp:ListItem>
                        </asp:DropDownList>

Open in new window

0
 
TommyBoy1980Author Commented:
Yep, I have checked the source code and the selected="selected" appears in the option element.

I have also tried the code added and the onselectedIndexChanged didn't fire when I returned to value1 from value 2

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Carl TawnSystems and Integration DeveloperCommented:
When/how are you binding your dropdown?
0
 
Alfred A.Commented:
Hi,

I just tried adding your dropdownlist to a test web form and it works fine.  I played changing from 1 to 2 and 2 to 1, it fires.

Can you provide more information on what is going on in your changedField_SelectedIndexChanged?  If possible, can you show us your code-behind code?
0
 
TommyBoy1980Author Commented:
This is the code behind. (its probably something so stupid)

protected void changedField_SelectedIndexChanged(object sender, EventArgs e)
        {
                numberPerPage = Convert.ToInt32(itemsPerPage.SelectedValue);                
                orderBy = sortBy.SelectedValue.ToString();
                buildSearchResults(viewBy.SelectedValue.ToString());
                
                // Rebuild the new Paging URLs
                buildPagingSearchURL(numberPerPage.ToString());

                // Change the pagin
                itemRange.Text = Pagination.getItemRange(numberPerPage.ToString(), Convert.ToInt32(itemCount));
            
        }

Open in new window

0
 
TommyBoy1980Author Commented:
I just thought I also have 2 other drop downs using the same code onSelectedIndexChanged code would this have an effect?
0
 
Alfred A.Commented:
Hi,

There is a possibility that one of your functions is stopping postback once you selected the second item.  This might be due to an error.

Do you have any javascript code that is being called in the event?    
0
 
Alfred A.Commented:
--------->  I just thought I also have 2 other drop downs using the same code onSelectedIndexChanged code would this have an effect?

Just tested it.  It works fine.  The correct sender is being captured for every change in selection.
0
 
Alfred A.Commented:
OK.  Can you try incorporating this unit code at the last line in the event and check the SelectedValue output?

DropDownList test = (DropDownList)sender;
string str = test.SelectedValue;
Response.Write(str);

Run this and check the value for each selection.
0
 
TommyBoy1980Author Commented:
Found the Issue, the EnableViewState was set to false!!

I'm guessing this caused a problem as the viewstate would store the selected data and if it wasn't in there then it would know if the index had changed.

Thanks

Tom
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.