Is it possible to dynamically assign a CommandArgument to an asp.net button using JavaScript?

My GridView has a list of items where one of the columns contains a link that triggers a modal display using AjaxToolkit ModalPopupExtender. This link is labeled as "Show". Inside the modal, there is an asp:button for saving the data entered, which is labeled as "Save".

When a user clicks on the "Show" link in a specific row, I want to implement JavaScript that modifies something in the "Save" button. This will allow me to handle the "Save".Command in my code-behind and utilize the CommandEventArgs parameter to access the value.

Is it possible to achieve this through JavaScript manipulation or do I need to resort to using a hidden input tag and setting its value instead?

Answer №1

While this may not directly address your specific question, there is an alternative solution that could potentially resolve the issue at hand:

Consider implementing a HiddenField element within your webpage. Within the backend code, assign the ID of the selected row (or any other identifying value) to this hidden field before triggering the modal popup. Subsequently, when handling the Save button functionality in your backend logic, you can easily retrieve the stored value from the HiddenField.

Answer №2

Upon further investigation, it appears that the task is unachievable. The CommandArgument attribute seems to be stored in the ViewState and cannot be manipulated with javascript as it is strictly server side.

Answer №3

To effectively utilize the UpdatePanel, ensure that the HiddenField is placed within. Failing to do so may result in the inability to access or modify the hidden field value.

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

Handling 401 Status Codes with Access and Refresh Tokens in a React and Node Application

Dealing with a 401 status request from my server when the access token is expired is proving to be a challenge. I have implemented accessTokenVerify on the server side: require('dotenv').config(); const jwt = require("jsonwebtoken") ...

Submitting data to an ASP.NET web service from an iOS app

I set up an ASP.NET Web service that I successfully tested on the server using the auto-generated service webpage. However, I am encountering difficulties when trying to post data to it through an iOS app. Despite receiving no errors, the method of the we ...

What could be causing the 404 Ajax not found error in my script?

I'm facing an issue with my code. When I try to run it, I encounter the following error: 404 (Not Found) while using the get method. Here is my html code snippet. <html> <head> <title>Issue</title> <meta charset= ...

Animating CSS using JavaScript

Recently diving into the world of JavaScript, I've taken on the challenge of creating an analog clock. I began by crafting the second hand using CSS but now I'm eager to transition it to Javascript without relying on jQuery or any other JS framew ...

Tips on utilizing the .ashx file for running scripts upon a webpage closing by a user

Is it possible to trigger some vb.net scripts when a user closes a webpage? I have some code but I'm not sure how to implement it. I came across the following instructions, but I'm having trouble using them: You can attach an ajax call to the "b ...

What is the method used by three.js to render video with spherical UV mapping?

I have a streaming video displayed in a 3*3 format. I am able to splice the entire video into individual sections using THREE, // Creating a 3x3 PlaneGeometry var geometry = new THREE.PlaneGeometry(400, 200, 3, 3); const video1 = document.getElem ...

What is the best way to use CSS in ReactJS to insert an image into a specific area or shape?

Currently, I'm working on developing a team picker tool specifically for Overwatch. The layout consists of cards arranged horizontally on a website, all appearing as blank gray placeholders. These cards are positioned using the JSX code snippet shown ...

Simulating a click event on a file input using .click() method is ineffective on iOS when using Cordova framework

I am currently utilizing React to construct a web application that is wrapped with Cordova in order to function as a native app on both android and iOS platforms. The challenge I am facing specifically pertains to iOS, particularly when attempting to simul ...

Create an array of routes specifically for private access using Private Route

In my application, I have defined different routes for admins, employees, and clients. Admins can access routes /x, /y, and /z, employees can access routes /a and /b, and everyone including clients can access 4 other routes. I am trying to implement this l ...

Encountering a 500 internal server error on the Azure web API

In my web api project developed using visual studio 2013 update 4 with EF6 on a Windows 8.1 Pro PC, I have the following connection string generated by EF: <connectionStrings> <add name="bcsmdbEntities" connectionString="metadata=res://*/BCSMMode ...

Animate the transition effect as soon as the block is displayed

Looking to create a smooth page transition using CSS changes with the help of Javascript (jQuery). Initially, one of the pages is set to display none. page1 = $('.page1'); page2 = $('.page2'); page1.removeClass('animate').cs ...

Progressive rendering of a substantial mesh using three.js

How can I efficiently render a large static mesh in three.js, even if it's 2 GB with tens of millions of polygons? My plan is to stream the mesh geometry buffers into indexedDB and render them progressively to the screen, all while maintaining an int ...

Creating or updating JSON files using Node.js

I am currently working with JSON files that contain an array of objects. I am looking to update one of these objects and subsequently update the JSON file by overwriting the old file. I understand that this cannot be achieved using AngularJS, but rather wi ...

Vuex is exclusively eliminating the initial element

Currently, I have set up the code to remove the activeNote from the array called notes by using the DELETE_NOTE mutation. However, it seems that it only removes the first element of the array. The content of mutations.js is as follows: export const mutat ...

Execute a Jquery function when clicking on a particular element using the .map method

Hey there, I'm working with an Array that looks like this: let myArray = [ {name:"try1", id:"id1", symbol:"symbol1"}, {name:"try2", id:"id2", symbol:"symbol2"}, {name:"try3", id:"id3", symbol:"symbol3"}, {name:"try4", id:"id4", symbol: ...

The data provided is not in the correct format for a timestamp

Currently, I am utilizing the pg node module to establish a connection with PostgreSQL, and I have been attempting to run the following query: const res = await client.query(`SELECT number_transactions FROM transaction.city_unique_dates WHERE date_day_t ...

Is it possible to create a unit test for a JavaScript function that manipulates an HTML element?

I'm struggling with testing a function that includes a modal displayer like this: function modaldisplayer(){ $('.mymodal').modal('show'); return 'success'; } In my code, there is another function called 'foo&a ...

Create HTML content dynamically with JavaScript and then utilize AngularJS to interpret and render it

I am creating an HTML table that looks like this: <table id="#webappname"> <tr ng-repeat="data in d"> <td>1 {{data}}</td> <td>2 hey !</td> </tr> </table> To create this, I am using a ...

Error: Document expected to be found has already been removed

Upon attempting to log into the app, I encountered an error message in the client console (chrome dev tools) that reads as follows: Uncaught Error: Expected to find a document already present for removed mongo.js?69942a86515ec397dfd8cbb0a151a0eefdd9560d:2 ...

Show the login page first before allowing the comment to be submitted in PHP

My objective is to show the login page before allowing a user to submit a comment. If the user is not logged in and tries to click on the submit button, they should be redirected to the login page. However, if the user is already logged in, the comment s ...