.net 3.5 - DropDownList won't persist

M

musosdev

Hi

I have a .net 3.5 web application. It's quite complicated (nested master
pages) and all is fine, apart from my DropDownList won't persist the selected
value.

My Master Page hierarchy is as follows...

Main Master
-- Section Master
-- -- Content Page
-- -- -- ASP:Repeater
-- -- -- -- HeaderTemplate
-- -- -- -- -- DropDownList that doesn't remember!

As far as I can tell, all the Master pages, the content page, and the
repeater have "EnableViewState" set to TRUE.

The list is populated in the ASPX (not the codebehind), so that should be
fine?!

My code fires an OnSelectedIndexChanged event which grabs the value from the
DropDownList (which works fine), but then when the page reappears, the
selected ListItem is back at the default?

What's going on?! Thanks!
 
S

Sreenivas

Hi

I have a .net 3.5 web application. It's quite complicated (nested master
pages) and all is fine, apart from my DropDownList won't persist the selected
value.

My Master Page hierarchy is as follows...

Main Master
-- Section Master
-- -- Content Page
-- -- -- ASP:Repeater
-- -- -- -- HeaderTemplate
-- -- -- -- -- DropDownList that doesn't remember!

As far as I can tell, all the Master pages, the content page, and the
repeater have "EnableViewState" set to TRUE.

The list is populated in the ASPX (not the codebehind), so that should be
fine?!

My code fires an OnSelectedIndexChanged event which grabs the value from the
DropDownList (which works fine), but then when the page reappears, the
selected ListItem is back at the default?

What's going on?! Thanks!

Did u set EnableViewState property of DropDownList to true?
Any code for OnSelectedIndexChanged would be much appreciated.
 
M

musosdev

Thanks for the reply.

EnableViewState is set to True on the DropDownList, the Repeater that the
list is in, and the <asp:Content> that it all resides in.

The OnSelectedIndexChanged event is defined as follows...

protected void sortDocs(object sender, System.EventArgs e)
{
DropDownList list = (DropDownList)sender;

order_by = " ORDER BY " + list.SelectedValue.ToString();


order_by += " DESC";

Session["library_list_orderby"] = order_by;

Debug.WriteLine(order_by);
}

The function works, the order changes based on my order by clause, but the
DropDownList always shows the first item.

Thanks
 
N

nateastle

Thanks for the reply.

EnableViewState is set to True on the DropDownList, the Repeater that the
list is in, and the <asp:Content> that it all resides in.

The OnSelectedIndexChanged event is defined as follows...

protected void sortDocs(object sender, System.EventArgs e)
    {
        DropDownList list = (DropDownList)sender;

        order_by = " ORDER BY " + list.SelectedValue.ToString();

            order_by += " DESC";

        Session["library_list_orderby"] = order_by;

        Debug.WriteLine(order_by);
    }

The function works, the order changes based on my order by clause, but the
DropDownList always shows the first item.

Thanks



Did u set EnableViewState property of DropDownList to true?
Any code for OnSelectedIndexChanged would be much appreciated.- Hide quoted text -

- Show quoted text -

when you rebind the dropdownlist what are you setting the selected
value / index to be?
 
M

musosdev

I'm not specifically rebinding it..

I've done a seperate test without master pages, just a DropDown in a panel
with an OnSelectedIndexChanged event, and everything else set the same.

Oddly, it works! So... what difference is the MasterPage making that causes
it to break? (the 2 nested masterpages being the only difference I can really
see...)

Thanks for the reply.

EnableViewState is set to True on the DropDownList, the Repeater that the
list is in, and the <asp:Content> that it all resides in.

The OnSelectedIndexChanged event is defined as follows...

protected void sortDocs(object sender, System.EventArgs e)
{
DropDownList list = (DropDownList)sender;

order_by = " ORDER BY " + list.SelectedValue.ToString();

order_by += " DESC";

Session["library_list_orderby"] = order_by;

Debug.WriteLine(order_by);
}

The function works, the order changes based on my order by clause, but the
DropDownList always shows the first item.

Thanks



Sreenivas said:
I have a .net 3.5 web application. It's quite complicated (nested master
pages) and all is fine, apart from my DropDownList won't persist the selected
value.
My Master Page hierarchy is as follows...
Main Master
-- Section Master
-- -- Content Page
-- -- -- ASP:Repeater
-- -- -- -- HeaderTemplate
-- -- -- -- -- DropDownList that doesn't remember!
As far as I can tell, all the Master pages, the content page, and the
repeater have "EnableViewState" set to TRUE.
The list is populated in the ASPX (not the codebehind), so that should be
fine?!
My code fires an OnSelectedIndexChanged event which grabs the value from the
DropDownList (which works fine), but then when the page reappears, the
selected ListItem is back at the default?
What's going on?! Thanks!
Did u set EnableViewState property of DropDownList to true?
Any code for OnSelectedIndexChanged would be much appreciated.- Hide quoted text -

- Show quoted text -

when you rebind the dropdownlist what are you setting the selected
value / index to be?
 
N

Norman Yuan

One possible reason is the dropdownlist' ListItem may contain duplicated
value, that is, more than one ListItem has the same ListItem.Value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top