Add info to txt file upon button click ASP.NET

Add info to txt file upon button click ASP.NET

I would like to store a int value(increases each time button is pressed) into a .txt file for each person.

I would like to store a int value(increases each time button is pressed) into a .txt file for each person.

I am clueless on how to store each individual's button value upon click. This is what i have came up with. Need help in this.

Actual question: Everybody who votes should be able to see the total number of votes as well as the vote of each candidate. You must use a file to record the vote.

@{

var dataFile = Server.MapPath(@"~/App_Data/data.txt");

string[] votesArr = File.ReadAllText(dataFile).Split(','); // your path
string toWrite = "";

for (int i = 0; i < votesArr.Length; i += 2)
{
    if (votesArr[i].Equals("Harry")) // Equals here is hardcoded, replace with parameter
    {
        votesArr[i + 1] = "" + (Int32.Parse(votesArr[i + 1]) + 1);
    }

    else if (votesArr[i].Equals("John")) // Equals here is hardcoded, replace with parameter
    {
        votesArr[i + 1] = "" + (Int32.Parse(votesArr[i + 1]) + 1);
    }

    else if (votesArr[i].Equals("May")) // Equals here is hardcoded, replace with parameter
    {
        votesArr[i + 1] = "" + (Int32.Parse(votesArr[i + 1]) + 1);
    }
    else if (votesArr[i].Equals("Jane")) // Equals here is hardcoded, replace with parameter
    {
        votesArr[i + 1] = "" + (Int32.Parse(votesArr[i + 1]) + 1);
    }

    toWrite += votesArr[i] + votesArr[i + 1];
}
File.WriteAllText(dataFile, toWrite);

} <!DOCTYPE html> <html> <head> <title>Elections</title> </head> <body> <p id="1">Harry</p> <input id="1" type="submit" value="Vote Harry">

&lt;p id="2"&gt;John&lt;/p&gt;
&lt;input id="2" type="submit" value="Vote John"&gt;

&lt;p id="3"&gt;May&lt;/p&gt;
&lt;input id="3" type="submit" value="Vote May"&gt;

&lt;p id="4"&gt;Jane&lt;/p&gt;
&lt;input id="4" type="submit" value="Vote Jane"&gt;

</body> </html>


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Jquery from validation || ASP NET Core client side validation

LIKE | COMMENT | SHARE | SUBSCRIBE In this video, I will show you how to add form validation using jquery. Subscribe & Stay Connected! Thank You! ♥ #Identity...

ASP.NET MVC Application with JQuery, AJAX

Let's have a sample example: We have a submit button in our JQuery AJAX MVC application. Let's try to show a message when it is clicked. ASP.NET MVC Application - Using JQuery, AJAX

Add asp.net Identity in empty project

LIKE | COMMENT | SHARE | SUBSCRIBE Today, in this tutorial you will see the process of adding an ASP.NET Identity to the ASP.NET Web Application developed in...