Two instances of the JavaScript confirm dialog appearing; Returning to previous page after clicking on an element

Newbie here, so please go easy on me.

I need help with a confirmation message for the User. My JavaScript is supposed to trigger a Button click event when the User confirms, which will execute some back-end code. The back-end code then runs a JavaScript function that displays an alert to check if everything is working fine. However, I'm facing an issue where after confirming the first dialog, another one pops up. Upon confirming this second dialog, the code executes and the second JavaScript function alerts as expected. But, upon clicking 'Okay' on the alert, the process loops back to the first function causing a problem!

ASPX:

<script type = "text/javascript">
function ConfirmComputerOverwrite(Computer) {          
    if (confirm("Overwrite current computer " + Computer + " ?"))
    {

    }
    else
    {

    }
    document.getElementById("Test").click()
}

function allworkedout()
{
    alert("success");
}

Code behind:

public string Computer = "";
protected void Page_Load(object sender, EventArgs e)
{
    string Computer = "Computer1";
    this.Computer = Computer;

    StringBuilder sb = new StringBuilder();
    sb.Append("ConfirmComputerOverwrite('" + Computer + "');");

    ScriptManager.RegisterStartupScript(this, GetType(), "ConfirmComputerOverwrite", sb.ToString(), true);
}

protected void Test_Click(object sender, EventArgs e)
{
    StringBuilder sb = new StringBuilder();
    sb.Append("allworkedout();");
    ScriptManager.RegisterStartupScript(this, GetType(), "allworkedoutID", sb.ToString(), true);
}

Grateful for any assistance!

Answer №1

When not using ajax, the entire page refreshes upon clicking, causing your javascript to run again and triggering confirmations, etc...

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

Tips for executing a JavaScript function within a secure sandbox environment

My current setup involves an application server developed in JavaScript (node.js) where I receive JS function code as input from a web browser. Now, my goal is to execute this function on the server without any interference with other processes. I am look ...

Looking to prevent the Digital Signature Public certificate BinarySecurityElement from being encoded in MTOM format

I'm stuck trying to solve a problem involving consuming a Java-based web service using WCF and WS-Security. When using non-MTOM requests, the public key certificate is sent as a base64 string within the BinarySecurityElement. However, for MTOM request ...

Encountering an async issue with npm exiftool in JavaScript

I'm facing issues with npm exiftool usage. (https://www.npmjs.com/package/exiftool) I'm attempting to perform some tasks using it. Iterate through image files in a specific folder Retrieve 'xpKeywords' data of each image file Write th ...

The RSS feed reader is currently malfunctioning

I'm having trouble loading an RSS feed from the following URL: http://solutions.astrology.com/scripts/it.dll?cust_id=aamfha&doc=daily07short/dailyshort.xml Here is the code I am using to try to read it: url = 'http://solutions.astrology.co ...

Utilizing Selenium to interact with textfields and simulate triggering events, replicating human-like behavior

Currently, I am facing a challenge in testing a webpage using Selenium which has been developed using AngularJS. This particular webpage contains text fields that users need to fill out. As the user starts typing in these text fields, AngularJS captures ea ...

Issues of significant gravity occurring upon upgrading due to SignalR

It took me two days, but I finally managed to install the new SignalR. However, now I am encountering another issue. I seem to have either removed the specific Owin Assembly or somehow lost reference to it. I have thoroughly checked my bin, packages, and ...

Updates to Firebase data do not automatically reflect in Google Charts

I've successfully connected my Firebase to Google Charts, however I am facing an issue in displaying a 'no data' message when there is no data available. Currently, I have set a Firebase data value of 'NA' for a single user, which ...

Construct a string by combining the elements of a multi-dimensional array of children, organized into grouped

My task involves manipulating a complex, deeply nested array of nodes to create a specific query string structure. The desired format for the query string is as follows: (FULL_NAME="x" AND NOT(AGE="30" OR AGE="40" AND (ADDRESS ...

Running an npm audit on the project reveals numerous errors and vulnerabilities

After running npm audit on my React project, I was presented with an extensive list of issues that needed attention. # npm audit report postcss 7.0.0 - 8.2.9 Severity: moderate Regular Expression Denial of Service - https://npmjs.com/advisories/1693 fix ...

Next JS restricts XLSX to return only 100 objects as an array of arrays

I've developed a file upload system that reads Excel files and uploads data to a database (using Mongoose). After implementing the code, I noticed that when I use console.log(sheetData), it returns an array of arrays with objects inside. Each internal ...

The CreateAsync function in UserManager seems to be malfunctioning within the Identity system

Creating Users with Post Method [HttpPost] public async Task<IActionResult> Register() { User user = new User { Email = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c5d4f5a5d7c5b51 ...

Ways to separate the strings in angular JS

I'm looking to divide a string into two parts. For instance: www.example.com/page.html?abcdef123456 I want to split the above URL string and save the part that comes after the question mark (?) into a variable. Can anyone advise on how to accomplis ...

NodeJS web scraping on a site that uses JavaScript

Currently, I am utilizing the request method to extract data from a particular SoundCloud page. Upon loading, SoundCloud verifies if JavaScript is enabled before displaying the track list. However, during my scraping process, I am only receiving a basic H ...

What are some practical applications for jQuery.data and how can I access this data from the server side?

Is it possible to utilize the jQuery.data(this, "isDirty", "very") function on the server side in order to implement specific processing for textBox controls after a page postback? ...

Finding the perfect tune on YouTube: A step-by-step guide

Currently, I am attempting to select a particular song from a list on Youtube. To simplify things, I will refrain from sharing all my classes but instead provide you with the elements I am utilizing. IwebDriver _webdriver = new ChromeDriver(); _webdriver. ...

Chrome crashing due to toDataURL

Recently, I have been working on a Tile Renderer for three.js and so far, everything appears to be functioning correctly. The process is quite simple: a) It creates multiple cameras, b) Renders the scene using each camera c) Generates a 'toDataURL&a ...

Converting keyValue format into an Array in Angular using Typescript

Is there a way to change the key-value pair format into an array? I have received data in the following format and need to convert it into an array within a .TS file. countryNew: { IN: 159201 BD: 82500 PK: 14237 UA: 486 RU: 9825 } This needs to be transf ...

Exploring the differences between an XMLHTTP request and a string and establishing a callback mechanism

After being a silent observer for quite some time, I've finally mustered up the courage to make my first post here, so please be kind... My journey with Javascript has just begun, and although I plan on delving into jQuery eventually, for now, I am f ...

Can a calendar be generated using a repeater function?

Seeking advice on creating a calendar view of events retrieved from a database. Can this be achieved with a repeater control, or is there a better approach? Thanks in advance! ...

The useEffect hook is not successfully fetching data from the local db.json file

I'm attempting to emulate a Plant API by utilizing a db.json file (with relative path: src\plant-api\db.json), and passing it from the parent component (ItemList) to its child (Item) but I am facing an issue where no data is being displayed ...