Retrieve the text input values dynamically generated by Javascript and save them into a storage system using .Net C#

This post marks my inaugural attempt at resolving a persistent issue that has been plaguing me for several days now. The crux of the matter lies in the following block of HTML code:

<fieldset>
    <legend>Certifictions</legend>

    <div runat="server" id="divCert">
        <input runat="server" type="button" id="btnAddCert" class="Botones" value="Agregar Certificación" onclick="AddCertification()" />
        <input runat="server" type="button" id="btnRemoveCert"  class="Botones" value="Quitar Certificación" onclick="RemoveCert()"  />
        <br/>
    </div>
</fieldset>

The crux of the challenge revolves around dynamically adding and removing text fields to divCert through JavaScript. Here's the pertinent code snippet:

var count1=0; 
function AddCertification() {
    document.getElementById("divCert").innerHTML += 
        "<input type='Text' runat='server' name='txCert_" + 
        (count + 1) + "' class='textBox' id='txCert" + (count1 + 1) + 
        "' placeholder='Insert Text'/>";

    count1 = count1 + 1;       
}

function RemoveCert() {
    var parent;
    var eleRemove
    if (count1 > 0) {
        parent = document.getElementById("divCert");
        eleRemove = document.getElementById("txCert" + (count1).toString());
        parent.removeChild(eleRemove);

        count1 = count1 - 1;
    }else {
        window.alert("There's nothing to remove");
    }
}

My ultimate objective is to retrieve the value of each textbox generated within the codebehind file, store this information, and subsequently write it into a separate file. A prospective solution might look something akin to the following:

List<Object> list = new List<object>();
    foreach(TextBox found in divCer.Controls){
    list.Add(found.Value);
}

I am acutely aware that the aforementioned code snippet will not function as intended, however, the essence of this endeavor is to extract values from each dynamically-generated textbox.

Answer №1

If there is no specific need for a server-side instance of these controls, you can easily obtain their values using

Request.Form["txCert" + i];

You can pass the count to the server side and use i to loop through the count variable.

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

Encountering difficulties initiating multiple projects in Visual Studio

I'm facing an issue that I can't quite pinpoint. It seems to work fine for a few times, but then this problem pops up: https://i.sstatic.net/JBgAs.png Launching a single project is no problem, but when trying to start multiple projects simultane ...

Trigger a notification from one webpage to another (PHP, JavaScript, HTML)

I'm currently working on a website that consists of both a receptionist page and a user page with multiple logins. The receptionist page displays a table listing all logged-in users, including their status (either ready or busy). This table is refresh ...

Unable to retrieve the value property from document.getElementById as it is null

Can someone help me with reading the input field value in my code? <input type="text" name="acadp_fields[1200]" class="text" placeholder="" value="December 26, 1969"> Here is the code snippet I am us ...

Utilizing HTTPS for ASP.NET API endpoints is essential for ensuring secure data

I have an asp.net application where I am utilizing HTTP controllers (ApiController) like so: [Route("api/dashboard/{id}")] [HttpGet] public DataTable getDashboardDetails(int ID) { } Both my web application and controllers exist within the same applicatio ...

Develop a mobile application using Visual Studio to direct users to a specific website

Operating System : Windows 10 with creators update. Visual Studio Community Edition. We have a website and would like to link it to our Visual Studio app. Is it possible to create an app in Visual Studio where we can run our website within a container? C ...

Node - Employing the exported function within the current file

While attempting to utilize the function I have exported within the same file, I encounter an undefined error: $(document).ready(function(){ $.get('https://apiEndpoint.com) .done(function(data) { for (var key in data.subscript ...

How can you call a function in ExpressJS that is located in a different file?

I am having trouble with my UserController and database configuration file db.js. I am trying to make a function in the UserController access a function in db.js. In my UserController, I have included var db = require('../config/db'); and within ...

Determining the file path relative to the project/src directory in Node.js

Currently, in my node.js project I am utilizing log4js and aiming to include the file name where the log record was added. However, when using __filename, it provides me with the absolute path. var logger = log4js.getLogger(__filename) This results in lo ...

The alpha value returned by gl.readPixels in Three.js will consistently be 255

Is there a way to retrieve pixel values from a threejs application? const gl = renderer.context; const currentFrame = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4); // read image data from gl gl.readPixels(0, 0, gl.drawingBufferWidth ...

Steps for Disabling Autocomplete in a JSP Page

How can I prevent the browser from remembering the username and password on my JSP page after submitting the form? I've already tried using autocomplete=off in the JSP code. <form name="indexFrm" id="indexFrm" autocomplete="off" method="post"> ...

Encountering a Newtonsoft.json issue while working on Xamarin Studio development

Hey everyone, I'm encountering an error while debugging my application. I'm trying to retrieve data from an SQL database and format it into a JSON string. My goal is to create an array of elements (A) containing their information (B1)(B2)(B3)(B4) ...

Can you explain the meaning of the code snippet i = (i + 1 == count) ? 0 : i + 1;?

I recently utilized this particular line of code in my jQuery plugin, but I find myself struggling to fully grasp its functionality. Below is a snippet of the plugin's code: Could someone provide me with an explanation? (function ($) { $.simpleS ...

"Use Node.js to make an HTTP GET request and retrieve the content

Here is the function I created: http://pastebin.com/xaE5Gpks The issue arises when the page occasionally returns a header 302, indicating a transfer. In these cases, my function stops at this page. How can I modify the function to continue to the new link ...

Utilizing the this.setState function within a callback

In my current project, I've encountered an issue with setting the state in a Twitter timeline react component. The code snippet causing trouble is as follows: componentWillMount: function() { twitter.get('statuses/user_timeline', ...

Guide to enhancing jQuery tooltip plugin with ajax support - integrating live functionality

I am currently using a jQuery plugin from However, I am facing an issue where the plugin does not work properly when using Ajax. I would like to modify or add a function live() to address this problem. Here is the complete code: http://pastebin.com/up6KY ...

Accessing all users' Start menu through programming

Is there a way to programmatically access the "All Users" Startup Menu? In XP, you can find it here: C:\Documents and Settings\All Users\Start Menu\Programs\Startup And in Windows 7, it's located here: C:\ProgramData& ...

What can you do to prevent a div from taking up the entire page if its height is not specified?

Currently, I am experiencing an issue with my layout. I have a hidden div with a fixed position that becomes visible when a button on the page is clicked. Inside this div, there is a table of buttons for the user to choose from. The problem arises when I ...

Retrieve specified elements from Bootstrap SelectPicker

My coffee selection script uses the Bootstrap SelectPicker plug-in to choose my favorite coffees. After submitting the form, I want to save the selected values and send them to addCoffee.php?coffee=${coffee}. How can I achieve this? HTML: < ...

Transferring API information into a nested array and displaying the outcome

Currently, I am utilizing an API to fetch an array of users from which I sort them and collect those with a personalTrainerId matching my userId into an array. The ultimate goal is to render these users as cards on the interface. The desired format for th ...

My locale NUXT JavaScript files are being blocked by Content Security Policy

I've been working on implementing CSP headers for my website to ensure data is loaded from trusted sources. However, I'm facing an issue where CSP is blocking my local JS files. Here's a snippet from my nuxt.config.js: const self = 'lo ...