【问题标题】:Clear Select2 Listbox not clearing codebehide Listbox.text清除 Select2 Listbox 不清除代码隐藏 Listbox.text
【发布时间】:2016-02-02 10:32:03
【问题描述】:

我有一个带有 select2 插件的列表框:

标记:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false" style="top: 400px; position: absolute; z-index: 0;">
    <ContentTemplate>

    </ContentTemplate>
    <Triggers>

    </Triggers>
</asp:UpdatePanel>

<asp:ListBox ID="Cliente" class="select2-select" runat="server" style="width: 100%">
    <asp:ListItem></asp:ListItem>
    <asp:ListItem>Value 1</asp:ListItem>
    <asp:ListItem>Vale 2</asp:ListItem>
</asp:ListBox>

Javascript:

    $('.select2-select').select2({
        maximumSelectionLength: 1,
        allowClear: true,
        placeholder: "Select..."
    });
    $(".select2-select").on("select2:select", function (e) {
        refreshPanel();
    });
    $(".select2-select").on("select2:unselect", function (e) {
        refreshPanel();
    });

    function refreshPanel() {
        __doPostBack("<%=UpdatePanel1.UniqueID%>", '');
    }

VB.NET

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    dim test as string = listbox.text

结束子

面板已正确更新,一切正常,但是当我清除 Listbox 时,__postback 被触发,但 listbox.text 仍然包含最后一个值。

我该如何解决这个问题?

---------编辑------------

我使用右侧的小十字清除列表框。

【问题讨论】:

  • 如何清除?
  • @Andrei 我用右边的小十字清除了列表框,正如您在编辑中看到的那样。

标签: javascript asp.net vb.net listbox select2


【解决方案1】:

这也许可行

test.value.clear

或:

 listBox1.Items.Clear

【讨论】:

  • 删除所有项目,我需要这些项目。 :) 我认为回发有一些问题。
猜你喜欢
  • 2014-11-24
  • 1970-01-01
  • 2020-01-08
  • 2012-07-05
  • 2012-02-24
  • 2013-07-14
  • 1970-01-01
  • 2020-04-07
  • 2018-07-02
相关资源
最近更新 更多