开发者

ASP.Net ListBox selections not working in Panel?

开发者 https://www.devze.com 2022-12-28 15:09 出处:网络
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 wor

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 item开发者_如何学Gos</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?


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
}


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号