简体   繁体   English

jquery切换与链接按钮无法正常工作

[英]jquery toggle doesn't work fine with link button

y have a <div> tag that show a gridview that contains a LinkButton to show it detail, in the header of the div tag I have a button to toggle the <div , this Works great, I want that when i click on the linkbutton of the gridview, the gridview toggle, with this code, looks like it going to work but it make the effect to toggle but inmediatly and automaticaly show again.你有一个<div>标签,它显示一个包含 LinkBut​​ton 的 gridview 来显示它的详细信息,在div标签的标题中,我有一个按钮来切换<div ,这很好用,我希望当我点击链接按钮时的gridview,gridview 切换,使用此代码,看起来它会工作,但它使效果切换但立即和自动再次显示。 this is my asp code这是我的asp代码

<span class="expande_button expandeSurtido" data-ref="parciales"><i class="fa fa-chevron-circle-up">
  </i>Expandir documentos</span>
  <div id="parciales">
    <asp:GridView ID="uxGridViewPartials" runat="server" AutoGenerateColumns="false" Visible="false" Width="50%" >  
       <Columns>
        <asp:BoundField DataField="documentNumber" HeaderText="Folio" ItemStyle-CssClass="tdCenter" />
        <asp:BoundField DataField="date" HeaderText="Fecha" DataFormatString="{0:d}" ItemStyle-CssClass="tdCenter"/>                                
        <asp:TemplateField HeaderText="Seleccionar">
        <ItemTemplate>
          <div class="app_acciones divCentrar">
           <asp:LinkButton ID="uxLinkButtonSeleccionar" runat="server" Visible="true" 
            CssClass="app_button contrae" data-ref="parciales"
            OnClick="uxLinkButtonSeleccionar_Click"                                            
            CausesValidation="False">Ver
            </asp:LinkButton>                            
         </div>                            
        </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="pkProductDocument"  ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" />
        </Columns>
        <HeaderStyle CssClass="HeaderStyle" />
        <RowStyle HorizontalAlign="Center" />                            
      </asp:GridView>
   </div>

and this is my js这是我的js

$('#contenedor').on("click", '.expandeSurtido', function() {
    $(this).children('i').toggleClass('fa-chevron-circle-down', 'fa-chevron-circle-up');
    $idPanel = $(this).attr('data-ref');
    $('#' + $idPanel).toggle("slow");
});

$('#contenedor').on("click", '.contrae', function() {
    $idPanel = $(this).attr('data-ref');
    $('#' + $idPanel).toggle("slow");
});

In mention, as you can see all is contained on a div with class called contenedor提到,正如您所看到的,所有内容都包含在一个名为 contenedor 的类中

The problem is that "OnClick" handers in ASP.NET web forms are server side functions, which then re-render the page after they are complete.问题在于 ASP.NET Web 表单中的“OnClick”处理程序是服务器端函数,然后在它们完成后重新呈现页面。

You're handler is working just fine, but then immediately returns to the server to deal with the click handler, and then re-renders the page (with the toggling reset to it's default state).您的处理程序工作正常,但随后立即返回服务器以处理点击处理程序,然后重新呈现页面(切换重置为其默认状态)。

You shouldn't be using LinkButton for this (since those are pretty heavily tied to server controls).您不应该为此使用 LinkBut​​ton(因为它们与服务器控件密切相关)。 Just make it an a tag: <a href="#" class="contenedor">Ver</a> and add the handler to that, and it should work fine.只需将其设为标签: <a href="#" class="contenedor">Ver</a>并将处理程序添加到其中,它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM