4

I want my selectable to work as an autopostback control, when something is selected the script clicks on a button and postback the values of the selectable. 但它不能很好地与我的 ASP.NET Ajax 和 UpdatePanels 配合使用。有时会发生完整的回发,而不是部分回发。

我从调试中得出的结论是,当停止函数运行时,jQuery 在幕后做了一些事情。如果我添加警报以停止停止功能,则部分回发可以正常工作。

为了增加一些混乱,这适用于IE9and Chrome,但不适用于IE7or IE8。所以它也可能是特定于浏览器的。

jQuery版本为:v1.6.2

脚本:

<script language="javascript">
    $('.selectable').live("mouseover", function () {
        if (!$(this).data("selectable-init")) {
            $(this).data("selectable-init", true);

            $(this).selectable({
                filter: '.item',
                stop: function () {
                    $("#<% =btnPostback.ClientID %>").click();                        
                }
            });
        }
    });    
</script>

HTML:

<div class="selectable">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
    <div class="item">4</div>
</div>

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:Literal ID="litIsPostback" runat="server"></asp:Literal>
        <asp:Button ID="btnPostback" runat="server" OnClick="btnPostback_OnClick" />
    </ContentTemplate>
</asp:UpdatePanel>

后面的代码:

protected void btnPostback_OnClick(object sender, EventArgs e)
{
    litIsPostback.Text = ScriptManager.GetCurrent(this).IsInAsyncPostBack.ToString();
}
4

1 回答 1

0

这是最接近我提出的解决方案。

        $('.selectable').selectable({
            filter: '.item',
            stop: function (event, ui) {
                $('.ui-selectable-helper').remove();

                setTimeout(function () {
                    $("#<% =btnPostback.ClientID %>").click();
                }, 1);
            }
        });

通过在回发之前删除助手(套索),我可以从上到下拖动,但我不能以其他方式进行。在 jQuery 中,帮助器在停止事件之后被删除。

我不确定为什么 setTimeout 有效,但它也解决了完整回发的问题。

于 2012-10-02T08:43:57.003 回答