【问题标题】:JQuery Draggable stops working inside updatepanel after a postback回发后,JQuery Draggable 在更新面板中停止工作
【发布时间】:2017-01-22 08:34:27
【问题描述】:

我有一个 asp.net 更新面板,里面有一些 devexpress 控件。

 <asp:UpdatePanel ID="upInsertPartNumber" runat="server">
     <ContentTemplate>
         <div id="divSAFRReceivingPanel" style="width: 50%; position: fixed;">          
             <dx:ASPxFormLayout runat="server" ID="frmControlPanel" AlignItemCaptionsInAllGroups="True">
                    ...  textbox here
                    ...  submit button here
             </dx:ASPxFormLayout>
         </div>

还有一个 div,我已将 jquery 可拖动行为附加到。当它第一次加载时,它工作正常。但是,一旦我提交表单,div 就会被设置为其原始位置并失去其可拖动性。

JQuery:

$(function () {
    ResetPanel();
});

function ResetPanel() {
    $('#divSAFRReceivingPanel').draggable({ revert: 'false' });             
}

理想情况下,即使在提交表单后,我也希望可拖动的 div 保持其位置和可拖动性。关于如何做到这一点的任何想法?谢谢!

【问题讨论】:

  • 表单正在通过ajax调用提交?

标签: jquery asp.net jquery-ui


【解决方案1】:

嗯,那是因为当你引发一个事件回发发生,并且只有更新面板中的内容被刷新,所以,你的元素失去回发之前的功能。

你可以做的是:

  • 在回发之前跟踪 div 的位置
  • 当回发发生时,从服务器端(C#)向客户端(浏览器)发送一些 javascript,可能是这样的

    ClientScript.RegisterStartupScript(this.GetType(), "ResetPanelWithPosition();", funcCall); 
    
  • 创建一个函数ResetPanelWithPosition(),重新附加可拖动行为并设置您在第一步中存储的最后一个位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    • 2017-03-17
    • 2010-09-13
    • 2023-04-08
    • 2013-05-08
    • 2017-04-20
    相关资源
    最近更新 更多