asp.netbuttongridviewpostbackasynchronous-postback

How to remove postback on linkbutton inside gridview?


I'd like to ask on how to prevent post back when a LinkButton inside the GridView is clicked?

My current implementation is that, I have a GridView with customer details and the button link which is the ID link button, once this link button is clicked the customer details will be shown on their respective fields (i.e. textbox, etc), but I want it to look like more interactive and faster when clicking the said button by removing Post back. How can I achieve this? Thanks.


Solution

  • So just to confirm my answer after our comments, replace this...

    <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="linkView" CssClass="View" Text ='<%# Eval("ID")%>' runat="server"></asp:LinkButton> </ItemTemplate> </asp:TemplateField>
    

    ...with this...

    <asp:TemplateField> <ItemTemplate> <a href="#" onclick="return loadViaAjax();"><%# Eval("ID")%></a> </ItemTemplate> </asp:TemplateField>
    

    ...where loadViaAjax is a Javascript function which populates your customer fields via AJAX or some other means. Ensure this function returns false to prevent the browser responding to the anchor click.

    Please mark this as the answer if it works for you.