Reputation: 16309
I'm having trouble processing a listbox after selecting some items from it. In my markup, the listbox is contained within an asp:panel and is populated during page load in the codebehind. That part works fine.
It's when I select various items and submit that I have trouble. My handler loops through the listbox items but doesn't see any as being selected. I'm not sure why.
Here's the markup:
<asp:Panel ID="panEdit" runat="server" Height="180px" Width="400px" CssClass="ModalWindow">
<table width="100%">
<asp:label runat = "server">Choose your items</asp:label>
<tr>
<td>
<asp:ListBox ID="lstFundList" runat="server" SelectionMode="Multiple" OnLoad="lstFundList_LoadData">
</asp:ListBox>
</td>
</tr>
</table>
<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_OnClick"/>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClientClick="$find('ModalPopupExtender1').hide(); return false;" />
</asp:Panel>
In my btnUpdate_OnClick
handler I can't see any listbox items that are marked as selected. I assume something strange is going on with respect to postback and the panel?
Upvotes: 0
Views: 1030
Reputation: 16309
Thanks everyone. Sure enough, it turned out to be an IsPostBack issue. It's used in all of our pages (and no doubt yours) and had become a sort of background noise, and I simply missed it here.
Upvotes: 0
Reputation: 1118
I agree, it's most likely a postback problem. Make sure the code that is populating the listbox is wrapped in something like this:
if (!Page.IsPostBack)
{
// populate your list
}
Upvotes: 1
Reputation: 85665
...is populated during page load in the codebehind
Is that wrapped in an IsPostback
conditional? If not, then you're just overwriting the returned values.
`OnLoad="lstFundList_LoadData"
You may want to check that method too....
Upvotes: 1