Choosing jQuery results in full postback in an ASP.NET Ajax application

I want my selection to work as an auto-repeat control, when something is selected, the script clicks on the button and returns the values โ€‹โ€‹of the selected values. But it does not play well with my ASP.NET Ajax and UpdatePanels. Sometimes a complete reverse transmission occurs, not a partial one.

My conclusion from my debugging is that jQuery does something behind the scenes while the break function is running. If I add a warning to stop the stop function, the partial postback works fine.

To add even more confusion, this works in IE9 and Chrome , but not in IE7 or IE8 . Thus, it may also be browser specific.

JQuery Version: v1.6.2

Script:

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

Code behind:

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

This is the closest to the solution I came up with.

  $('.selectable').selectable({ filter: '.item', stop: function (event, ui) { $('.ui-selectable-helper').remove(); setTimeout(function () { $("#<% =btnPostback.ClientID %>").click(); }, 1); } }); 

By removing the helper (lasso) before the postback, I can drag from top to bottom, but I cannot do it differently. In jQuery, the helper is removed after the stop event.

I'm not sure why setTimeout works, but it also fixes a problem with full postback.

0
source

Source: https://habr.com/ru/post/1436610/


All Articles