views:

92

answers:

3

Hi everyone,

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?

+1  A: 

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

Mark Brackett
+1  A: 

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
}
jaltiere
A: 

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.

larryq