Getting the string value from JavaScript within an ASP.NET control

I am struggling with incorporating the output of a JavaScript function into an ASP page.

 function getListOfUidMeter(){
    input = "";
    var tbl = document.getElementById('tableStripy'), i;
    for (i = 0; i < tbl.rows.length; i++) {
        input = input + tbl.rows[i].cells[11].outerText).split(",")[0] + ",";
    }
    return input;
}

The mentioned function returns a string, but I need to access this result within an ASP page and utilize it.

<form name="Form1" method="post" onkeypress="if (event.keyCode==13) {this.submit();event.returnValue=false;} else event.returnValue=true;">
<input class="lookup" type=hidden name="Id" value="<%=PageParams1.Id%>">
<!-- Other hidden input fields are listed here -->

</tr><tr>
                        <td>
                            <!--Additional hidden fields-->
                            <input type="hidden" name = "OLD_STATUS" value = "<%=oldstatus_str%>">
                            <input type="hidden" name = "X_LSUSER" value = "<%=username_web.toUpperCase()%>">
                            <input type="hidden" name = "X_LSTIME" value = "<%=data_modifica%>">
                        </td>
                    </tr>
</td>
</tr>
</table><!-- /SnapIn -->

<SCRIPT language="javascript">
getListOfUidMeter(); // Calling the JavaScript function to get the desired result
</SCRIPT>
    </form>
    </body></html>
    <% }     
    catch (e) {ReportError(e); } %>

The challenge lies in effectively transferring the outcome of the mentioned JavaScript function to be used within the ASP context.

Answer №1

When aiming to achieve this goal, utilizing hidden fields offers a straightforward solution:

  • Create a new hidden field, such as "hfTemp"

  • In your Javascript function, save the returned value in the designated hidden field.

    $get('hfTemp').value = input

  • In Asp.net after executing the JS function, implement:

(VB)

Dim JSValue As String = Request.Form("hfTemp")

(C#)

string JSValue = Request.Form("hfTemp");

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

Using a combination of radio buttons and JavaScript to adjust the color of a div element

Currently, I am experimenting with radio buttons to modify the background color of my div tag. My goal is to incorporate more than one condition. For example, if button A and button B are both clicked, then change the color to green. This is what I have im ...

What is the best way to display a Timepicker within a Dropdown menu using Angular?

While browsing the Bootstrap 4 documentation, I came across a toggleable dropdown feature for the timepicker. However, instead of using vanilla Bootstrap, I wanted to implement this functionality with an Angular module specifically designed for the timepic ...

Display Bootstrap modal automatically upon page load three times for each individual user

i need the bootstrap modal to appear on page load and i have come across the following code. However, there are a couple of issues: 1- I want the modal to display for every user three times, not just the first time! How can I achieve that, my friends? 2 ...

Error: The variable Ajax is unknown and has not been defined

I encountered an issue with my MyBB forum while using a plugin for advanced stats. The error in the console stated "Uncaught ReferenceError: Ajax is not defined", causing my website to fail in loading the latest posts from the top. Website: Below is the ...

Exploring the caching capabilities of NextJS and Vercel for optimizing simple fetch

I have successfully deployed a NextJS (13.2.4) app to Vercel after testing it locally with great results. The issue I am facing is related to a simple fetch request from a component ('use client'). This request is directed towards a route within ...

How to retrieve the value of a <td> tag with a rowspan greater than one using JQuery

I have a dynamic table that depends on the quantity of data in the abc1 column. For example, in this instance, there are 2 rows in the abc1 column with values of 18 and 23 http://jsfiddle.net/SdN4L/ <table border=1> <tr> < ...

React component fails to render even after successful authentication check

Trying to set up a secure route for my application, I encountered an issue with React Hooks where the state is not updated directly. This causes a problem when trying to redirect unauthenticated users, as the initial render treats them as not logged in and ...

An error occurred: ECONNRESET was encountered while reading in TCP.onStreamRead within the internal/stream_base_commons module at line 217, character position

Currently, I am in the process of developing a web server specifically for the Mineflayer API as part of my coding project. This server is hosted through the free plan on render.com, and I have set up a cron job to ensure that it remains active. Despite my ...

Obtain the current URL in a Node.js configuration file

In my application using the express framework, I have the following code in my app.js file: var express = require('express'); var app = module.exports = express(); var config = require('./config.js')(app, express); // Including ...

Loop through the numbers entered into a table field

<table id="Container1Details" cellspacing="15"> <tbody> <tr> <td align="right"> <input name="acidity" type="number" maxlength="4" id="acidity" min="0.112" max="0.152" step="0.001" style= ...

What is the process for identifying a web application in .NET Core?

Currently, my code is running in a process that could be a Console application, a desktop application, or an ASP.NET application. I am attempting to identify the type of application in which I am operating. In the .NET framework, I can utilize HostingEnvi ...

What is the method used for defining an element within an array in JavaScript?

As I am new to JavaScript, I find myself trying to organize callbacks within an array. An example of what I have been working on: items = [ "test" = async message => { let userCoins = editCurrency('fetch', message.guild. ...

What is the best way to retrieve an object based on a custom key type in TypeScript when using a

I have a custom class called Foo: class Foo { constructor(public v: any) { } } And I have a map where Foo is my Key: const map = new Map<Foo, string>(); As far as I know, TypeScript does not support comparison overloading. How can I ensure ...

I am currently facing difficulties with properly injecting my service class into the constructor of my component in Angular 18

I've encountered an issue while working on a tutorial in Angular 18 that seems to be targeted towards an older version of the framework. Below is my Service class: export class ProductsService { getProducts() : string[] { return [& ...

Managing UTC calculations with date-fns library in Node.js: A complete guide

Having some trouble with the date-fns library when trying to manipulate UTC dates. When attempting to add or subtract dates, it seems like the library isn't handling them correctly. An example: > const { add } = require('date-fns'); undef ...

Using JavaScript to parse JSON data containing additional curly braces

Looking at this JSON object: var dataObj = { data: '\n{ sizeMap:{\nxSizes: "REGULAR|SMALL", \ncurrItemId: "",\ncurrItemSize: "",\nmanufacturerName:"Rapid",\npartNumber: "726G", \nsuitStyle: "R",\nhasSC: "",&bso ...

Executing a JavaScript function within a PHP echo statement

I am completely new to working with AJAX and PHP echo variables or arrays. However, I have managed to successfully display images on my website by passing variables from AJAX to PHP and back. The only problem I am encountering is when I try to call a Javas ...

various locations within a hexagonal zone or figure

In my project, I am working with a simple hexagonal grid. My goal is to select a group of hexagons and fill them with random points. Here is the step-by-step process of generating these points: I start by selecting hexagons using a list of hex coordinat ...

Best way to store extensive data tables in ReactJS

My application utilizes Flask as the backend and React as the frontend, processing vast amounts of data consisting of millions of rows. While sending this data from the backend (where it is stored in a Python dataframe) to the frontend in JSON format prov ...

Using w3-include-html with a relative URL path

Is there a way for me to use the same header HTML on multiple pages within subdirectories without having to duplicate the file itself? As shown in the code snippet below, the header file is located in both the current directory and parent directory. While ...