Swapping out LinkButtons using jQuery

[EXPLANATION] (apologies for the length)

In my gridview, users have the option to add a new entry or edit an existing one. When they click on either 'Add' or 'Edit', a popup window appears for them to input the information for the new or updated item.

Instead of creating two separate popups, I decided to use one popup with two different LinkButtons - one for adding a new record and the other for saving changes to an existing record (with editable fields). The visibility of these buttons needs to be controlled based on the user's action ('Add' or 'Edit').

To achieve this, I used jQuery to toggle the visibility of the buttons. While it worked fine when showing the 'Edit' save button upon clicking 'Edit', I encountered an issue with hiding the 'Add' save link when the user clicks 'Edit'. Even though I set the display property for the buttons correctly in the code, there was a problem with toggling their visibilities.

[QUESTION]

I debugged using Chrome and confirmed that the function is being executed, so I'm not sure what's causing the button visibility issue. Can anyone help me identify the problem?

[CODE]

.aspx

<%-- Edit button within GridView --%>
<asp:LinkButton ID="lbEditButton" runat="server" OnClientClick="showEditLink();" Text="Edit" CommandName="editCmd" CommandArgument='<%# ... %>'></asp:LinkButton>

<%-- Add button below GridView --%>
<asp:Button ID="btnAddCert" runat="server" Text="Add Certification" OnClientClick="javascript:showAddLink(); return false;" />

<%-- Save buttons inside ASPxPopupControl (DevExpress) --%gt;
<asp:LinkButton ID="lbAddSave" runat="server" CausesValidation="true" Text="Save" OnClick="lbAddSave_Click" />
<asp:LinkButton ID="lbEditSave" runat="server" CausesValidation="true" Text="Save" OnClick="lbEditSave_Click" />

jQuery

function showAddLink() {
        $("[id*='_lbEditSave']").css('display', 'none');
        $("[id*='_lbAddSave']").css('display', 'inline');
        pcPopup.Show();
        return false;
    }

    function showEditLink() {
        $("[id*='_lbEditSave']").css('display', 'inline');
        $("[id*='_lbAddSave']").css('display', 'none');
    }

Answer №1

I would just have one button, and set the text and the onClick based on whether the user was adding/editing. Something like this in your javascript for the add case:

function setUpForAdd() {
  var button = $('#buttonID');
  button.html('Add button text')
  button.click(addHandlerFunction);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to extract data from Azure Data Lake and showcase it within an Angular-2 interface?

I am facing a challenge where I need to retrieve files with content from Azure Data Lake and display them in an Angular-2 Component. The issue is that when using the List File Status() method, I am only able to obtain file properties, not the actual conten ...

Storing information during the click event of the Submit Button and before the Form Submission in the View

Below is the form that gets posted from the view to the action method. When the onclick() event is triggered, it calls jquery.ajax and sends data (content of the first div) to the same action method. The order of execution is such that jquery.ajax runs fir ...

Functionality of Ajax: Data fields containing numerous values

I'm confused about the data fields in the ajax function. Typically, the syntax for an ajax function looks something like this: $.ajax({ url: "/aaa/bbb/ccc", method: "SomeMethod", data: someData, success: function (res ...

Issues with visuals in jQuery.animate

I have nearly finished implementing a slide down drawer using jQuery. The functionality I am working on involves expanding the drawer downwards to reveal its content when the handle labeled "show" is clicked, and then sliding the drawer back up when the ha ...

Retrieving CSS style values with Node.js

I am looking to design a new CSS style that includes the lowest and highest values. table[my-type="myStyle"] { width: 255.388px !important; } This code snippet is included in numerous CSS files within my style directory. ...

substitute bullet point list item with new element

Assuming I have a list: <ul class="ul-1"> <li class="li-1">xx -1</li> <li class="li-2">xx -2</li> <li class="li-3">xx -3</li> </ul> Then I store it as: var list = $('.ul-1').html(); In ...

ASP.NET - Enabling File Upload on PostBack via Trigger

Within my UpdatePanel, I have an upload control and a button for uploading. The button is configured as a trigger, but the event handler does not run on the initial PostBack. This is how my ASPX code looks: <asp:UpdatePanel ID="updPages" runat="server ...

Using jQuery to interact with a web service - overcoming cross-domain restrictions

Attempting to connect to a WCF service using a jQuery client. Referencing this specific example: http://www.codeproject.com/KB/aspnet/WCF_JQUERY_ASMX.aspx#4 Everything functions properly when the client webpage is on the same domain as the service. Howe ...

The wordpress jquery dependency is failing to respond

After converting an HTML ecommerce template into WooCommerce, I am experiencing issues with the functionality. The Nivo slider and some other product features are not working properly. It seems like they are having trouble finding WordPress jQuery, even th ...

Because of the CSS tree structure, it is not possible to add or remove classes. This restriction applies to all actions done in jQuery, including click

I want to create a hover effect where the CSS changes when hovering over an item, then reverts back to normal when no longer hovered. Additionally, I would like the CSS to change when the item is selected, and return to normal when another item in the same ...

Tips on making a fresh form appear during the registration process

After clicking on a submit button labeled as "continue" within a form, a new form will appear for you to complete in order to continue the registration process. ...

Exploring the Relationship Between jQuery and JSON through Iterating Over JSON Arrays

There is an array stored in a database: a:4:{i:1;s:4:"1993";i:2;s:4:"1994";i:3;s:4:"1995";i:4;s:4:"1996";} To manipulate this array, I first unserialize it using PHP and then encode it with JSON. The code snippet is as follows: $unwp = unserialize(&apos ...

The jQuery UI dialog box is malfunctioning and failing to return a value when the user clicks a button

I have a jQuery UI dialog box that I want to use for confirming a deletion action with the user. The issue I am facing is that the code below seems to return "True" or "False" immediately when the dialog pops up, even before the user has clicked the "Yes" ...

How can I programmatically close the Date/Time Picker in Material UI Library?

Is there a way to programmatically close the Date/Time Picker in Material UI Library? ...

Fetching weather data from the Darksky.com API in JSON format

My goal is to retrieve weather data in JSON format from the Darksky.com API. To do this, I first successfully obtained my latitude and longitude using the freegoip.com API. However, the Darksky API requires both longitude and latitude before it can provid ...

Transferring information to a controller using ajax in ASP.NET Core

I am encountering an issue with sending data to the controller through ajax. The value goes as "null". Can someone please assist me with this? Here are my HTML codes: <div class="modal fade" id="sagTikMenuKategoriGuncelleModal" data ...

Is it considered a bad practice to use the record ID on a <tr> element for an editable row within a table?

I am in the process of using jQuery to create a feature that allows users to edit a HTML table containing category names. Currently, I have successfully populated my table using PHP/MySQL. While researching on jQuery - Edit a table row inline, I came acr ...

Creating a responsive DataTable filled from a $.ajax request is a straightforward process that can greatly

I am in the process of creating an application that retrieves a lot of data from a web-service query and populates a data table with it. The data shows up correctly and styled properly on desktop, but when I switch to viewing it on a mobile device, the dat ...

Guide to extracting the key of a JSON object with a numerical name

I am having trouble extracting JSON objects from my server that contain numbered names to distinguish them. When trying to retrieve these objects, I encounter an issue with appending numbers to the common name. The structure of the objects is as follows: ...

What is the best way to use jQuery to filter data in a table by clicking on a specific table row?

My website contains a table with player names and servers, but I want to make them clickable for filtering purposes. For instance, clicking on a player name should reload the leaderboards to show which servers that player plays on, and clicking on a server ...