ASP.Net 列表框选择在面板中不起作用?
从中选择一些项目后,我在处理列表框时遇到问题。在我的标记中,列表框包含在 asp:panel 中,并在代码隐藏的页面加载期间填充。那部分工作正常。
当我选择各种项目并提交时,我遇到了麻烦。我的处理程序循环遍历列表框项目,但没有看到任何被选择的项目。我不知道为什么。
这是标记:
<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>
在我的 btnUpdate_OnClick
处理程序中,我看不到任何标记为选中的列表框项目。我认为回发和面板方面发生了一些奇怪的事情?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我同意,这很可能是回发问题。确保填充列表框的代码包含在如下内容中:
I agree, it's most likely a postback problem. Make sure the code that is populating the listbox is wrapped in something like this:
是否包含在
IsPostback
条件中?如果没有,那么您只是覆盖返回值。您可能也想检查该方法......
Is that wrapped in an
IsPostback
conditional? If not, then you're just overwriting the returned values.You may want to check that method too....
谢谢大家。果然,原来是IsPostBack问题。它在我们所有的页面(毫无疑问也是你的)中使用,并且已经成为一种背景噪音,而我只是在这里错过了它。
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.