Using ASP.NET to validate a radiobutton list using JavaScript, followed by invoking a C# function

After experiencing some errors, I have refined my question to better articulate my objective. By revising the logic of my previous issue - where no text appeared in a pop-up dialog triggered by a C# script utilizing a JavaScript method - I present my updated inquiry:

My radio button group is set up as follows:

<asp:RadioButtonList ID="rblMyGroup" runat="server" 
     RepeatDirection="Horizontal">
     <asp:ListItem>Yes</asp:ListItem>
     <asp:ListItem Selected="True">No</asp:ListItem>
</asp:RadioButtonList>

In C#, how can I determine if "Yes" is selected? If it is, how do I prompt a pop-up message asking "Are you sure?" When the user selects yes, a specific method should be executed, while clicking cancel should result in no action. If "No" is chosen, the same method as for "Yes" should be triggered.

The C# method in question is named: myAwesomeMethod(string s). When this method is invoked, it will alter the text displayed on a button within the page. This simplification aims to enhance clarity and understanding of the problem at hand. Successfully resolving this issue will aid me in addressing other challenges I am currently facing.

Answer №1

Unsure if this is exactly what you're looking for, but the code needs to have instructions on what to do when the user clicks "Yes."

<script type="text/javascript>
    function validate() {
        var response = confirm('Are you sure?');

        if(response == true) {
           alert("You clicked OK!")
        } else {
           alert("You clicked Cancel!")
        }
    }
</script>

Additionally, check out this related question: Simple JavaScript problem: onClick confirm not preventing default action

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

Create a custom API that is able to send requests to a different API

I am currently working with an existing API that needs to fetch data from another external API. What is the best approach to achieve this? I attempted to use HTTPClient for this purpose, but I am encountering difficulties in making it work. The error mess ...

Manage shared nested modules across different modules in Vuex without redundancy

In my Vue.js application, I am using Vuex as the state manager. To ensure that certain states are shared across different components, I have created a nested state containing all the common information. This allows me to import it into multiple modules. F ...

Tooltip remains visible even after formatting in highcharts

I have successfully hidden the datalabels with 0 values by formatting them. However, after formatting the tooltips for 0 valued data in a pie chart, there is an issue where hovering over the 0 valued portion shows a white box as shown in the picture. I hav ...

Developing user registration and authentication using Backbone.js in conjunction with Django Rest Framework

In the process of developing my app, I am utilizing backbone.js for the frontend and django-rest-framework for the backend. My goal is to enable user registration, login, logout functionality, and be able to verify whether a user is logged in using backbon ...

The CollapsiblePanelExtender remains unresponsive

I am currently utilizing a CollapsiblePanelExtender in combination with a checkbox. The goal is to have the panel expand or collapse based on the checkbox being checked or unchecked. While this functionality does work, I am facing an issue where the panel ...

Is there a way to execute a script during every npm install process?

Is it possible to set up pre-push hooks for Git with each npm install action? Are there any alternative solutions that do not involve installing tools like Gulp, and instead rely solely on npm? ...

Struggling to locate a straightforward sidebar solution without relying on Bootstrap. Finding an easy-to-use answer seems

I have a lightweight and easy-to-understand code for a website project with two panels. The first panel on the left is a large navigation (270px width, top to bottom, similar to a wiki) with approximately 30 unordered list items. Next to it is the second ...

Accessing the return value from an ASP.NET web service in JavaScript outside of the callback function

I am facing an issue with my ASP.NET web service that returns a simple string value. I have successfully called this web service using JavaScript and the script manager. However, I am in need of accessing the return value directly from where I made the cal ...

Getting an image file to an API server using Node.js

I am looking to create an API server using node.js, and one of the requirements is to upload image files to it. While I have successfully implemented the logic for the GET method in my code, I am struggling with how to write the logic for the POST method ...

Guide to showcasing an image on an HTML page using HTTP header

I have an HTML page with a basic layout that includes a single button. When this button is clicked, it needs to trigger an HTTP request to a specific URL while including an Accept header for GET requests. The response from the HTTP URL will vary depending ...

When referencing a particular React commit in package.json, it may result in the installation of react-tools instead of react itself

After including the following line in my package.json: "react": "git://github.com/facebook/react.git#08e4420019f74b7c93e64f59c443970359102530" When I execute npm install, I notice that node_modules/react-tools has been installed instead of node_modules/r ...

typescript in conjunction with nested destructuring

ES6 has definitely made coding more efficient by reducing the number of lines, but relying solely on typescript for everything may not be the best approach. If I were to implement type checking for arguments that have been destructed multiple levels deep, ...

Is it possible to substitute the variables with the function name?

Is there a way to duplicate the variable name? Take a look at the example below (note the name a1) $(document).ready(function() { name = "a1"; // This is "NAME" as a1 }) function name() { // USING "NAME" $("#test" + name).keydown(function(a) ...

The gear icon in the video player is not showing up when I try to change the

I am currently trying to implement a feature that allows users to select the quality of the video. I am using videojs along with the videojs-quality-selector plugin, but even though the video runs successfully, the option to choose the quality is not appea ...

What could be causing my images not to show up when I use string interpolation for src links in Vue.js?

I've encountered an issue while working on Vue.js where I'm struggling to render a couple of images from the local directory. What puzzles me is that this problem arises when using string interpolation, like in the code snippet below: <img :s ...

Unleashing the power of pipeline and let parameters in C# using $lookup (MongoDB.Driver 2.7.2)

In my C# code working with MongoDB.Driver 2.7.2 and MongoDB 4.0, I am looking to execute the following query in MongoDB. Instead of using $project / $unwind, I prefer to use $lookup to avoid having to name each field in the collection individually. db.ge ...

Is the Order of a JSON Array Dependable?

When working with JSON, it's clear that relying on the ordering of key-value pairs may not be reliable. For instance, a JSON parser could interpret { "someKey" : "someValue", "anotherKey" : "anotherValue", "evenAnotherKey" : "evenAnotherV ...

Top method for verifying email existence in ASP.NET database

In our current asp.net web application, we are facing some challenges with using the update panel on the user registration page to check for existing users. These issues include: 1- The update panel tends to slow down the process. 2- The focus is lost wh ...

Tips for achieving compatibility between systemjs module loading and .net mvc architecture

Upon finding the ng-book 2, I saw it as a promising resource to delve into Angular 2. Although I am new to module loaders and have minimal experience with npm and node, I find the terminology and assumed knowledge to be quite perplexing. I decided to use ...

Retrieving Data from JSON File hosted on Azure Storage using C#

I am currently working with a JSON file stored in Azure Storage and accessing it using C#. Within this JSON file, there is a specific node called SQLViewDifinition that contains the SQL I need to retrieve. After reading the file into a string and converti ...