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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Carl TawnSystems and Integration DeveloperCommented:
When/how are you binding your dropdown?
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.