Updating GridView row only if there are changes, the value remains unchanged in JavaScript. Disappointing

Incorporating a gridview (ASP.net) inside an update panel, I included a "Save" button that triggers a loop through all the rows of the grid view to pass data to a stored procedure for updating each row. However, this process proved to be slow and resulted in database updates even when no changes occurred.

To address this issue, I made an adjustment by adding a hidden field within my gridview:

<asp:TemplateField>
      <ItemTemplate>
          <input type="hidden" id="hdnIsChanged" runat="server" />
      </ItemTemplate>
 </asp:TemplateField>

The idea behind adding this hidden field was to track any changes made to textboxes or dropdown values in a gridview row by updating the hidden field value to 1. This modification was implemented in the gvLineItems_RowDataBound event as follows:

Dim hiddenField As HtmlInputHidden = DirectCast(e.Row.FindControl("hdnIsChanged"), HtmlInputHidden)

    'Tracking line item date
    Dim tLID As TextBox = CType(e.Row.FindControl("txtLineItemDate"), TextBox)
    tLID.Attributes.Add("onchange", "document.getElementById('" + hiddenField.ClientID + "').value=1")

    'Tracking the amount field
    Dim ta As TextBox = CType(e.Row.FindControl("txtAmount"), TextBox)
    ta.Attributes.Add("onchange", "document.getElementById('" + hiddenField.ClientID + "').value=1")

The intention was to set the value to 1 upon change. Subsequently, in the save button function, the following logic would execute:

  For Each Row As GridViewRow In Me.gvLineItems.Rows

            Dim hiddenField As HtmlInputHidden = DirectCast(Row.FindControl("hdnIsChanged"), HtmlInputHidden)

            If (hiddenField.Value = "1") Then
              'perform the update...

The problem arises during debugging as the value of hiddenField.Value consistently remains at 1 whether there were actual changes made in the textbox or not. I came across a similar discussion on this forum thread.

While it seemed to have resolved the issue for others, I continue to face the challenge where the value always registers as 1...

Answer №1

When using the getElementById function, ensure to lowercase the last character 'd' in order to avoid any syntax errors.

Answer №2

Out of the blue, everything is running smoothly now. It appears that the issue was related to textboxes coupled with a calendarextender (ajax). I decided to remove the rowdatabound for this specific field and voila, problem solved...quite peculiar.

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

Troubleshooting the issue: "Error - 'Missing "data" payload in the request' when using Vue.js with Strapi"

When attempting to create a new entry in strapi by sending a post request in vue.js, I encountered the following error: message: Missing "data" payload in the request P.S: I also need to be able to upload files. I have read that using formData is ...

Unexpected outcomes arising from using nested arrays with jQuery validation plugin

I have been utilizing the jQuery validation plugin from . I am encountering an issue with validating a nested array "tax_percents[]" that is within another array. The validation seems to only work for the first value in the array, and even for the second f ...

Validation within nested Joi schemas

Need help validating a nested object conditionally based on a parent value. const schema = Joi.object({ a: Joi.string(), b: Joi.object({ c: Joi.when(Joi.ref('..a'), { is: 'foo', then: Joi.number().valid(1), otherwise: Jo ...

Is it possible for me to choose to establish a new scope within a directive?

Encountered an issue while reusing a directive where some tags had a second directive with a new scope created using new or {}, while others did not have one. Attempting to create a new scope when one already existed resulted in an error being thrown by An ...

Send the appropriate data once the response has been completed

My Express.JS server has multiple res.json responses. In order to conduct statistics, logging, and debugging, I am looking to capture the response payload using a universal hook. While I have come across the finish event res.on('finish'), I am s ...

Tips for invoking a PHP function with jquery

I'm facing a bit of an issue with my code. I have a button that, when clicked, should execute a PHP function defined in the same file. Although the "clicked" alert appears upon clicking the button, I'm not getting any response from the function. ...

Clicking on AngularJS ng-click to navigate to a different page within an Ionic framework application

My goal is to navigate to another page when clicking on a button in the Ionic navbar at the top. However, I am encountering an issue where upon clicking, all nav bar buttons disappear. Interestingly, using dummy codes triggers an alert successfully. But w ...

Retrieve information from a .json file using the fetch API

I have created an external JSON and I am trying to retrieve data from it. The GET request on the JSON is functioning correctly, as I have tested it using Postman. Here is my code: import "./Feedback.css"; import { useState, useEffect } from " ...

React Native: struggling to fetch the most up-to-date information from an array

I'm working on a chat application that functions similar to a chatbot. Since I don't want to use a database and the messages are temporary, I opted to utilize JavaScript arrays. Whenever a user inputs a message in the TextInput and hits the butto ...

React Redux Connect MapState not refreshing when filtering an item from a list

It seems like I may have misunderstood something or made a mistake when trying to subscribe to changes on a specific item within a collection in my store. My component isn't receiving updates unless I directly subscribe to the list. The following cod ...

Insert an element at the start of a sorted array object

I am currently working on a small application that has the following structure: Posts -> Post -> Comments -> Comment. The Posts component sends a request for an array of posts sorted by date in descending order. Each post also fetches its comment ...

Encountering issues when implementing react-router with the client-side library

After following the author's suggestion, I've successfully loaded the client-side library. The recommended method is to simply drop a <script> tag in your page and use the UMD/global build hosted on cdnjs. I have ensured that ReactRouter i ...

What does the "done" callback function entail in Node.js?

Many npm packages commonly utilize a "done" callback function in their code. I find it challenging to grasp its purpose. For instance: passport.serializeUser(function(user, done) { done(null, user.id); }); From what I can gather: The "done" function a ...

How can we implement a select-all and deselect-all feature in Vue Element UI for a multi-select with filtering capability?

As a newcomer to VueJs, I am exploring how to create a component that enables multiple selection with a search option and the ability to select all or deselect all options. To achieve this functionality, I am utilizing the vue-element-ui library. You can ...

Is there a way to have a span update its color upon clicking a link?

I have 4 Spans and I'm looking to create an interactive feature where clicking a link in a span changes the color of that span. Additionally, when another link in a different span is clicked, the color of that span changes while reverting the previous ...

What is the best way to attach an attribute to a element created dynamically in Angular2+?

After reviewing resources like this and this, I've run into issues trying to set attributes on dynamically generated elements within a custom component (<c-tabs>). Relevant Elements https://i.stack.imgur.com/9HoC2.png HTML <c-tabs #mainCom ...

Find the total number of duplicate elements in a JavaScript array

I'm using an ajax call to retrieve values from a JSON structure and pushing them into a JavaScript array with .push for each iteration. However, I have multiple instances of the same value (e.g. person's name) in the array and I want to count the ...

Apollo Client is not properly sending non-server-side rendered requests in conjunction with Next.js

I'm facing a challenge where only server-side requests are being transmitted by the Apollo Client. As far as I know, there should be a client created during initialization in the _app file for non-SSR requests, and another when an SSR request is requi ...

I'm confused why this code is functioning in JSFiddle but not on my HTML webpage

For the first time, I am encountering this issue. I am currently attempting to integrate this code into my application http://jsfiddle.net/TC6Gr/119/ My attempts include: Pasting all the jsfiddle code in a new page without my code, but it doesn't w ...

Transformation of looks post a refresh

Initially, the CSS and appearance of the page look fine when I first open it (after clearing the cache). However, upon refreshing the page, a part of it changes (specifically, the padding direction of a div). This change occurs consistently with each refre ...