Guide on accessing a button inside an item template within an asp.net "gridview" through Javascript

As a beginner programmer, I have encountered an issue with a gridview that contains a button repeated in every row. This button is part of an item template and when clicked by the user, it should change the value of another textbox column using JavaScript. Although my initial attempt seemed to work perfectly, I noticed that when clicking the button in a row, the text of the corresponding textbox changes momentarily before disappearing, as if there was a postback occurring. How can I prevent this behavior?

OnclientClick ="myFunct(this)"

function myFunc(x){
   var id=x.id;
   var newID = id.substring(0, 18);
   newID+="TextBox1";
   document.getElementById(newID).value="ghjhghjg";
}

Regards

Answer №1

Hurray! The solution has been discovered. All that's required is to include a "return false" statement in the onClientClick function to prevent postBack.

function updateValue(y){
    var identifier = y.id;
    var newIdentifier = identifier.substring(0, 18);
    newIdentifier += "TextBox1";
    document.getElementById(newIdentifier).value = "updated value here";
    return false;
}

onclientClick="return updateValue()"

That's all it takes!

Answer №2

If you want to give this a go using jQuery

$('#' + mytable + ' input[id$=btnEntry]').on("click", function () { });

Appreciate your help Anna

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 FindByIdAndUpdate function is successfully updating the data, but it is unexpectedly

This is my first time seeking guidance here, as I've reached a dead end with my issue. I am currently working on a household collection that includes a member collection within it. Whenever new members join, I need to update the household collection ...

Building an array of ids that contain the checkbox type using jQuery: What's the best way?

Below is the HTML snippet I am working with: <!-- Parent checkbox code goes here --> <input id="ckbCheckAll" class="custom-check ez-hide" type="checkbox" name=""></input> <!-- Child checkbox codes follow --> <input id="practice_ ...

Center-aligned footer with a sleek right border in Bootstrap 4.1.1

Presenting my design concept for the footer: https://i.sstatic.net/kxdXJ.png Here is the code snippet for the footer design utilizing Bootstrap 4.1.1: .mainfooter-area { background: #404044; padding: 100px 0; } ... <link href="https://cdnjs.cl ...

Having trouble with fetching data in React from a URL?

When attempting to send a post request to a specific URL without proxy settings, I encountered a CORS error. After setting up a proxy, the URL was still pointing to localhost. The error persists even after attaching my proxyfile.js and including the code s ...

Why is the origin null being blocked by Access-Control-Allow-Origin in an android web view?:1?

I encountered an issue with the following error message: XMLHttpRequest cannot load http://192.168.1.33:8080/ws/target. Origin null is not allowed by Access-Control-Allow-Origin.:1 When attempting to load a html page on a webview, I include the script ta ...

When Bootstrap4 modals are positioned towards the bottom of the page, tapping on an input field inside the modal causes the page to scroll to the bottom on Chrome for Android

Can you please take a look at this issue? I have a simple one-page HTML code that reproduces it. There are two modals on the page - one at the top and one at the bottom. The problem occurs when tapping on an input field inside the bottom modal, causing the ...

`How can I change the background on my MasterPage in ASP.NET as a web developer?`

Can someone assist me with setting the background for my main page in ASP.NET as a web developer? Also, how can I set different color backgrounds for other pages (such as making page 1 gray and page 2 blue)? Apologies for any mistakes in my English. Than ...

Tips and tricks for activating javax.script in Websphere liberty profile on Bluemix

I am looking to incorporate JavaScript into one of my Java applications. In order to test this, I executed the following code: javax.script.ScriptEngineManager manager = new ScriptEngineManager(); javax.script.ScriptEngine engine = manager.getEngineByName ...

Attempting to showcase a collection of values, specifically focusing on highlighting the even numbers within the array

const sampleArray = [ 469, " " + 755, " " + 244, " " + 245, " " + 758, " " + 450, " " + 302, " " + 20, " " + 712, " " + 71, " " + 456, ...

How to generate PDF downloads with PHP using FPDF

I am attempting to create a PDF using FPDF in PHP. Here is my AJAX call: form = $('#caw_auto_form'); validator = form.validate(); data = form.serializeObject(); valid = validator.form(); //alert("here"); ajax('pos/pos_api.php',data,fun ...

Struggling with dragging Vue.js modals?

I am currently utilizing the vue-js-modal library, and I'm encountering an issue with it. Whenever I set my modal to be draggable by using :draggable="true", I can drag it around but then I am unable to input any text in the form fields. It seems to c ...

Combining shared table rows with embedded ruby code in Javascript - is it possible?

I'm a new Javascript learner and I'm attempting to create a function that will merge rows with the same value (year in this case) and add their numbers together. Although my code isn't functioning as expected, it also doesn't seem to be ...

Utilize AngularJS's JSON datetime filter with user input

Here is the filter function I created to convert JSON date: app.filter("mydate", function () { var re = /\/Date\(([0-9]*)\)\//; return function (x) { var m = x.match(re); if (m) return new Date(parseInt(m[1])); else return ...

Exploring the JsonArray Response entity

Trying to decode my fetch response: fetch('restservices/users/', fetchOptions) .then(function (response) { if (response.ok) { console.log('1'); console.log(response) const responseSjon = response.json ...

Guide to making axios/api calls in a Nativescript mobile application

In my development process, I am working on creating a small application using Nativescript-vue. This application requires backend functionality that is built on the laravel framework for making API calls to retrieve relevant data. For example, when a user ...

Applying a class to a single div element

I am struggling with adding a class to a specific div only if it contains an image. <div class="large-6 columns check-Div"> <div class="custom-table"> <div class="text"> <?php echo $latestimage; ?> </div> ...

Sending non-textual data within a JQuery ajax POST request

I have encountered an issue related to sending data from a JavaScript application to a Node.js server for database query purposes. Despite trying to find a solution from various sources, I have been unable to resolve it. Here is the code snippet used to s ...

The idea of a webpage completely powered by Ajax

I'm currently in the process of creating a compact website that utilizes full ajax requests for features such as login and registration, all done asynchronously. However, I've come across an issue where if a user decides to refresh the site, any ...

getting information from component in NextJS

Apologies if this question is too basic. I recently started my journey into learning React and NextJS. I am working on a simple application that fetches data and displays it on the Home page. In my component file, I have two functions. This component file ...

What is the best way to successfully send an object through AJAX once all its updates are completed?

I am experiencing an issue with my JavaScript code within an event: var userData = tableWidget.grid('userData'); console.log(tableWidget.grid('userData')); $.ajax({ "url": "../../server/query.aspx?tableEvent=reordercolumns&tabl ...