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

The button works properly in JSFiddle, however, it is not able to clear the ordered list in the

DEMO Creating a script that captures mouse click coordinates and appends them to a list. The functionality works, except for an issue with the clear button not working properly. After making corrections in jsfiddle, the script functions correctly. Howeve ...

Tips for creating an element that maintains its dimensions when a border is added during a hover effect

One issue I often face is the desire to add a border to an element on hover, only to find that as the border appears, the element's height and width change, causing it to visually jump and potentially push other elements. Is there a solution for this ...

Develop an XML document that includes CSS and DTD seamlessly incorporated

Could someone please provide me with a short code example of an XML file that includes both a DTD and CSS styles all in one file? Just need one element as an example. I'm new to XML and can't seem to find any examples with both XML and CSS comb ...

Having difficulty making a selection on the intermediate action page

I am working with two models User and Group. I am creating a new action called "Change Groups" in UsersAdmin. This action will redirect to an intermediary page with 2 MultipleChoiceFields for Groups. These fields will allow users to either remove users f ...

Record client's real-time decision in the database

Is it possible to use jQuery to update a specific cell in phpMyAdmin after adding a div to a particular group? Take a look at the code below: <div id="item1">Item 1 <input type="button" value="put me in Group1" name ...

show pictures in a grid section

My gridview is set up to display images in each row, but I'm encountering issues with binding an imagecolumn to a dynamic URL. In the codebehind, I populate a datatable with records, define the gridview columns programmatically (as it cannot be done i ...

Performing slow SQL executions (invoking stored procedures) on a massive website

Initially, I acknowledge that my inquiry might be broad, but please bear with me as I have spent a month pondering on how to articulate it and still feel uncertain about expressing my concerns. Currently, I am in the process of developing a website intend ...

Choosing Between EMs and Pixels for Font Sizes: A 2011 Perspective

In the past, EMs were favored over pixels for font size because they could scale with IE6 while pixels could not. Nowadays, modern browsers can handle pixel-sized font scaling correctly. Another advantage of EMs is that they cascade, unlike pixels. But if ...

Having trouble with the functionality of expanding rows in Kendo grid

I am facing an issue with my Kendo grid that is populated from a SQL database. The expand feature works perfectly and displays a different Kendo grid in the expanded row when the program is first launched. However, if I perform a new search and get differe ...

The CSS float puzzle - text alignment dilemma

Recently, I created a simple float-based banner with tiles which you can see here on jsfiddle. However, I encountered a major issue with centering text in each tile. My goal is to have all the "Sample text" content centered both horizontally and vertically ...

I am having trouble compiling sass in VS Code using the sass --watch command

I've encountered an issue while trying to compile sass through the terminal. Despite having already installed node.js and successfully using Live Sass, I consistently receive the following error message: sass : The term 'sass' is not recogni ...

The values are not being displayed in the local storage checkbox

I attempted to transfer checkbox values to another HTML page using local storage, however they were not appearing on the other page Here is my page1 HTML code snippet: <input class="checkbox" type="checkbox" id="option1" name="car1" value="BMW"> ...

Tips for incorporating a notification bar below the header

I'm fairly new to CSS and I'd like to create a black notification bar for free shipping right below the header, with white text. It needs to span the full width of the browser. I attempted to achieve this using CSS and `header::after`, but my te ...

Tips for limiting the text in video player controls to fit within a specific container

I'm having an issue with my video player where the controls scale incorrectly when the window size changes. Does anyone know how to make the "time-total", "time-played" and "timeline" elements follow the boundaries of the "video-controls" div like the ...

In HTML5, a full-width video exceeds the size of the screen

When I have a video set to full width in a header with the width at 100%, the issue arises with the height. The video is too large, causing the controls to be out of view unless I scroll. Is there a solution to remedy this problem? <video width="100%" ...

Hide using jQuery only if the element is currently visible, and show using jQuery only if

Is it possible to manipulate the visibility of a div using jQuery without repeatedly adding classes? Can an if statement be used for this purpose? For example: $(document).ready(function() { $(".trigger").click(function() { // Hide the div only if i ...

Chrome's keyup event restricts the use of arrow keys in text fields

Could you please test this on Google Chrome browser: jQuery('#tien_cong').keyup(function(e) { jQuery(this).val(jQuery(this).val().replace(".", ",")); var sum = 0; var tien_cong = jQuery('#tien_cong').val(); tien_cong = tien_ ...

magnify within a div with a set width

Looking for a way to make a div both zoomable and scrollable within a fixed-width container using transform: scale(aScaleRatio) for zooming in/out. Check out this demo for achieving the zoom effect. However, the inner div seems to have trouble aligning to ...

Angular has the capability to rewrite URLs in CSS, providing a unique way

An issue arises in Angular when using a base set and html5mode with SVGs. This causes things like filter: url(#url) to be rewritten as filter: url(/base/#url). https://github.com/angular/angular.js/issues/8934 Disabling html5 mode and removing the base d ...

Ways to showcase the contents of a React JavaScript document, or more specifically, a file designed for React interpretation

After trying multiple solutions, I found a conceptual guide on How to call and form a React.js function from HTML. However, the HTML generated doesn't seem to be calling from the JavaScript file as expected. It appears identical to what is mentioned i ...