Is it true that pressing cancel on the Javascript Confirm does not halt the request during a post back?

When using a Javascript function with a confirm() message box and RequiredFieldValidator, if the cancel button is pressed on the confirm message box but the ValidatorGroup is true, it does not prevent the request from being posted back.

I am looking to modify this behavior so that even if the validatorGroup is true, if the function returns false, the request should not be posted back.

Below is my code snippet:

<asp:Button ID="btnStaffSendRequest" runat="server" Text="Send" OnClientClick="UploadRefrrel()"
                        UseSubmitBehavior="false" ValidationGroup="SaveRequestGroup" OnClick="btnStaffSendRequest_OnClick"
                        TabIndex="1000" />

And here is my Javascript function:

<script language="javascript" type="text/javascript">

                            function UploadRefrrel() {
                                var hiddenFile = this.document.getElementById("<%= hfInputForm.ClientID %>");
                                var upload = $find("<%= radUploadFiles.ClientID %>");
                                var inputs = upload.getUploadedFiles();
                                var retVal;
                                if (hiddenFile != null && hiddenFile.value != "" && inputs.length == 0) {
                                    retVal = confirm("FYI - Only 'Referral Form' is attached. Do you want to proceed without any other attachment?");
                                }
                                return retVal;
                            }
                        </script>

Answer №1

<asp:CustomValidator ID="validateFileAttachment" runat="server" Display="None" ClientValidationFunction="Validate_FileAttachment"
                        ValidationGroup="SaveRequestGroup" ErrorMessage="<br /> Please include an additional attachment."></asp:CustomValidator>                  
                    <telerik:RadScriptBlock ID="uploadReferralForm" runat="server">
                    <script language="javascript" type="text/javascript">
                        function Validate_FileAttachment(sender, e) {
                            var hiddenField = this.document.getElementById("<%= hfInputAttachments.ClientID %>");
                            var uploader = $find("<%= radUploadFiles.ClientID %>");
                            var uploadedFiles = uploader.getUploadedFiles();

                            if (hiddenField != null && hiddenField.value != "" && uploadedFiles.length == 0) {
                                var response = confirm("Note - Only the 'Referral Form' is attached. Do you wish to continue without any other attachments?");
                                if (response == true) {
                                    e.IsValid = true;
                                }
                                else {
                                    e.IsValid = false;
                                }
                            }
                        }
                    </script>
                    </telerik:RadScriptBlock>

Resolved my issue and everything is functioning properly.

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

Remove an option from a drop-down menu once a different option has been selected (using Jquery)

I need to remove an item (ItemX) from a dropdown menu (Drop Down 2) when ItemX is selected in Drop Down 1 using jQuery. This is how I am approaching it: <?php session_start (); ?> <!doctype html> <html lang="en"> <head> <ti ...

Utilizing ionic-scroll for seamless movement and scrolling of a canvas element

I have set up a canvas element with a large image and I want to enable dragging using ionic-scroll. Following the provided example: <ion-scroll zooming="true" direction="xy" style="width: 500px; height: 500px"> <div style="width: 5000px; h ...

Issue with Asp.NET Web API returning 404 errors instead of 400

I've developed a service using .NET 4.5 and Entity Framework 6, with the ASP.NET Web API template. The issue I'm facing is that when sending a GET request to the service without a required parameter, I receive a 404 - Not Found error instead of a ...

Challenges with declarations and operators

Hi everyone, I'm trying to tweak the order of operators in a code snippet so that the result logged is 0. Can someone help me figure this out? numbers = [23, 12, 71, 10] operators = [ (a, b) => a + b, (a, b) => a / b, (a, b) => a * b, (a, b) ...

tips for deleting spacing in the <pre> element

I need help with formatting my text within <pre></pre> tags. The issue I'm facing is that there is an indent on the first line and I want to remove it. Can someone assist me in modifying this code to achieve that? @foreach (v ...

Looking for a pattern that combines Browserify and Angular?

Currently, I am embarking on a project using angular and browserify for the first time. I am seeking advice on how to properly utilize the require function with browserify. There are multiple ways to import files, but so far, I have experimented with the ...

Using JavaScript to Establish Default Homepage in FireFox and Internet Explorer

How can I set a web address as the default homepage for a client? Specifically looking for solutions for (pageload) on IE8 and Firefox 3 (or newer versions). Thank you in advance for your help. Best regards ...

React - input value for creating a numerical outcome is not functioning as expected

I'm currently in the process of learning React and have encountered an issue with my input field. I am attempting to have the input receive a number and then pass that number when the submit button is clicked. Most of the functionality is working as e ...

The maximum value of the slider corresponds to the total number of elements in the array

As I work on constructing a Material UI Slider, I have a specific requirement. I want the maximum value of my slider to dynamically adjust according to the number of items in an array of options. ['Answer1', 'Answer2', 'Answer3&ap ...

What is the proper syntax for creating a layout with DIV and CSS?

Is there a way to create a master page for asp.net that includes 3 sections using div elements? I want to split the window into a left pane for tree view navigation, a top banner type div, and a main content window under it where child pages will be loaded ...

Validating a string as a date input by utilizing the moment library

Utilizing the momentjs library for validating dates can be tricky. The typical format for validation is as follows: moment(date, formats, true).isValid() However, if you only want to check if a string is a valid date without specifying a format, things ...

Ensure that the callback response in the $.ajax() function is treated as JSON dataType

My code snippet: <script> $('#email').on('blur', function(){ email = $(tihs).val(); $.ajax({ type: "POST", url: "ajax.php", data: { 'email': email, ...

Steps to transfer a JavaScript variable to a PHP session

Currently, I am in the process of retrieving the value of a checkbox and assigning it to a PHP session variable. Below is the relevant portion of the code: The checkbox: $html .= '<span><input type="checkbox" id="checkbox' ...

The Select2 widget passes parameter term spaces to the ajax request as a plus sign "+" instead of %20

I have been working on an application that connects to SAP's service layer and retrieves data using REST APIs. I am using the popular widget select2, but I have encountered a problem. The API query that needs to be made contains a space character arou ...

Execute multiple events using jQuery's .trigger() method

As I develop a jQuery plugin, I am utilizing the .on and .trigger functions for my pub/sub system. One challenge I am facing is triggering multiple events in different scenarios with ease. My question is whether it is possible to trigger multiple events a ...

Navigating with React Router Dom and parsing objects in search parameters

Currently, I am utilizing React Router Dom v6 and require the ability to retain object search parameters within the URL. My current approach involves: const [searchParams, setSearchParams] = useSearchParams(); const allSearchParams = useMemo(() => { ...

Conceal content after a specific duration and display an alternative in its position, continuously repeating the loop

Imagine creating a captivating performance that unfolds right before your eyes. Picture this: as soon as the page loads, the initial text gracefully fades away after just three seconds. In its place, a mesmerizing animation reveals the second text, which ...

A guide to parsing nested JSON with AngularJS

I am currently working on parsing a nested JSON using AngularJS. Here is an example of the nested JSON structure: { "results": [ { "id": "D1", "name": "A", }, { "id": "D2", "name": "B", } ] } Below is the Angul ...

"Mastering jQuery: A beginner's guide to iterating through tables using

Having trouble with a clock script in jQuery that fails when looping to change the last 2 digits of the time. Currently, only one row is being updated, but I need all rows to update. Here is the code snippet: $(document).ready(function(){ var jam ...

Top method for handling chained ajax requests with jQuery

I'm facing a scenario where I have to make 5 ajax calls. The second call should only be made once the first call returns a response, the third call after the second completes, and so on for the fourth and fifth calls. There are two approaches that I ...