Having trouble triggering the return confirm function before the button click event

I am currently working with a radbutton that triggers an SQL query to delete a record on its onclick event.

My goal is to display a confirmation message box before the deletion process, but I'm encountering difficulties in making it work as intended.

  • I attempted adding the confirm dialog to the onclientclick event,
  • I tried incorporating it into the attributes using code behind when the button click event occurs,
  • and I also experimented with
    Page.RegisterStartupScript("clientScript", message)
    .

Unfortunately, each of these methods results in the account being deleted prior to the confirmation prompt appearing.

When I temporarily disable the delete code, the message pops up successfully. In the case of adding it to the attributes, the confirmation only worked after clicking the delete button twice. Despite researching extensively for several days, I have not discovered a suitable solution yet. Any assistance would be greatly appreciated.

Updated - included code.

Various approaches I have tested:

    string message = "<script language=JavaScript> alert( ' The ' );</script>";

    if (!Page.IsStartupScriptRegistered("clientScript"))
    {
        Page.RegisterStartupScript("clientScript", message);
    }

And

    RadButton btn = (RadButton)sender;

    string strMessage = "Are you sure?";

    btn.Attributes.Add("onclick", "return confirm('" + strMessage + "');");

Here is the button

    <telerik:RadButton ID="btnDeleteAccount" runat="server" Font-Bold="True" Font-Names="Arial"
    Font-Size="11px" Skin="WebBlue" Text="Delete Account" OnClick="btnDeleteAccount_Click"
    Width="150px">
    </telerik:RadButton>

Answer №1

After much trial and error, I stumbled upon a snippet of code that actually did the trick. It seems like my previous attempts at javascript were incorrect.

Behold, the magic code that solved my problem:

OnClientClicking="function (sender, args){args.set_cancel(!window.confirm('Are you sure you want to delete this account?'));}"

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

Should I keep my Mobx stores in a dedicated file or include them directly in the React component?

There are a couple of ways to define observable properties and actions in MobX. One way is to include them directly in the component like this: // App.js class App extends Component { @observable a = 'something' @action change() { this. ...

HttpOnly Cookies are not received by the Chrome Node in Selenium Hub as expected

My Selenium tests are set up in two different ways: Running locally with Chrome WebDriver to create and implement the tests Executing them in a CI pipeline using Selenium Hub and a Chrome Node The backend of the application creates HttpOnly cookies, and ...

Is it safe to presume that any errors occurring within a promise will propagate to a new promise and be caught appropriately?

Within my function, I first check the cache for data. If it's not found, I fetch the data and store it in the cache. I'm curious about how errors are handled within nested functions. Will an error in the innermost function bubble up to the outerm ...

I receive a notification when I interact with a form in React on the internet

Encountering an error when a user fills out the form I'm constructing: react_devtools_backend.js:4026 Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined val ...

Modify the main element of App.config file for a .net application

Here is the typical starting point for App.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> Would it be feasible to substitute "configuration" with a different term like "StartingConfiguration"? ...

What is the process for sending a message from the internet to a mobile device?

We are currently in the process of developing a website that sends SMS alerts to users for specific services, however I am struggling to set up a script that can perform this function. If anyone has any suggestions or recommendations for a solution, pleas ...

The integration of Angular PWA is posing challenges with Angular Ivy

_ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | ...

What's the best way to switch between colors in a Vue list?

I have a custom tree-view component that I'm working on: <template> <li class="main__li list" :style="{'margin-left': `${depth * 20}px` ,'background-color': `${col}`}" @click="toggle(e); getEl( ...

Conceal a div when hovering above the navigation bar

Upon hovering over the second button in the menu, a "submenu" pops up covering part of the images within a div labeled as "container". The design of the submenu is somewhat translucent, causing the images inside the div "container" to faintly show through ...

The annoying pop-up refuses to vanish even after clicking on the "Stop Capture" button during screen recording

I'm dealing with an issue regarding popups. Whenever I choose "get audio from desktop" and click on "Start Recording", another browser popup appears, prompting me to make another decision (this involves selecting the screen and sharing audio). I' ...

What could be causing input to be blocked in certain situations while using my Angular directive with compile function?

Recently, I created a directive that adds a class based on a certain condition. You can find the code snippet at the end of this question. The directive functions as expected in a simple use case where it's applied to a required field: <input typ ...

"JQuery fetches the value from the previous instance rather than the current one

I'm having trouble with jQuery grabbing the current value of a textarea. I have multiple posts, each with a "write a review" button. When I click on the button for the first post, a dialog box pops up with the title of the first post and a textarea. H ...

Limiting the number of times a specific character appears using a regular expression

Currently, I am in search of a regular expression that allows me to set a limit on the number of times a special character can appear. For instance, if I want to restrict the occurrence of * to a maximum of 5 times in the entire text, then the output shou ...

Passing Data from Next.js Middleware to getServerSideProps during the Initial Request with the Help of Cookies

Encountering a challenge within a Next.js application (for a coding challenge). Requested flow to achieve: Check for geolocation cookie in Next middleware. If not present, fetch data and store in cookie. In getServerSideProps, utilize the cookie (if avai ...

Implementing a secure route in Next.js by utilizing a JWT token obtained from a customized backend system

Currently, I am in the process of developing a full-stack application utilizing NestJS for the backend and Next.js for the frontend. Within my NestJS backend, I have implemented stateless authentication using jwt and passport. My next goal is to establis ...

Tips for choosing multiple files with the Ctrl key in a list item element:

We have decided to create our own browsing functionality due to the limitations of the existing HTML browse feature. While using the HTML browse, we can only select multiple files by pressing the Ctrl key, and we want to replicate this feature in our custo ...

Checking types during code execution

When working with TypeScript on Node.js, types are checked during compilation. However, once the code is compiled to JavaScript, type checking is no longer enforced. This can lead to unexpected errors, as in the following example: var test: number; test = ...

When the user clicks, automatically direct them to a different webpage

I tried to create a changing background color effect in the following order: Black, White, Red, Green, Blue. <body style="background-color:black"> <script type="text/javascript"> function changeColor() { var currentBg ...

Tips for successfully passing array index as an image source in Vuejs with v-img?

Hi there! I'm currently attempting to cycle through an array of URLs and insert them into the src attribute. I'm struggling with the correct syntax to accomplish this task. Would you be able to lend a hand? I have an array named DataArray that co ...

Run a series of commands using a C# console application

I'm relatively new to programming and currently learning C#. I am looking to create a method in C# that will run the following commands via the console: - install Newman; - execute postman Run. After trying out two different options (ReadToEnd and Wa ...