The custom validation function fails to activate

One of the challenges I faced was with a gridview named gv1. It contains checkboxes, and at least one checkbox must be checked for processing. Despite having custom validation in place, it seems to not be functioning correctly. Below is an overview:

The Custom Validator configuration:

<asp:CustomValidator runat="server" ID="vldItemCus"
    ClientValidationFunction="ValidateSelection"
    Display="None" ErrorMessage="Select at least one item for update" ValidationGroup="Update"></asp:CustomValidator>

Validation Summary:

<asp:ValidationSummary ID="vldSummary" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="Update"></asp:ValidationSummary>

Javascript Function:

function ValidateSelection(source, args) {
    var found = 0;
    $('#gv1 input[type=checkbox]').each(function () {
        if (this.checked) {
            found = 1;
            return false;
        }
    });
    if (found == 1) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
    return;
}

Answer №1

Here is the updated version of the function:

function CheckSelection(source, args) {
    var checkCount = 0;
    $('#<%= checkBoxGrid.ClientID %> input[type=checkbox]').each(function () {
        if (this.checked) {
            checkCount = 1;
            return false;
        }
    });
    if (checkCount == 1) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
    return;
}

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

Are there any alternatives to Google Charts for creating charts?

There is a restriction of only 2k queries per month, which I find insufficient. Are there any alternative classes, plugins, or tools that can be used to generate charts similar to those created by Google Charts? Thank you. ...

How can you handle events on DOM elements that haven't been created yet in JavaScript?

In my JavaScript module, I have the following code: EntryController = function$entry(args) { MainView(); $('#target').click(function() { alert('Handler called!'); }); } The MainView() function includes a callback ...

React Native: struggling to fetch the most up-to-date information from an array

I'm working on a chat application that functions similar to a chatbot. Since I don't want to use a database and the messages are temporary, I opted to utilize JavaScript arrays. Whenever a user inputs a message in the TextInput and hits the butto ...

What is the technique for showing text in two different colors through a script?

What is the method to alternate text colors using a script? Display the text in color #ccc for 1 second, then switch to color #000 for 1 second, and finally return to color #ccc for 1 second (repeating in a loop). ...

An unexpected token was discovered by Jest: export { default as v1 } when using uuid

While working on writing Jest tests for my React component in a Monorepo, I encountered an error while running the Jest test. ● Test suite failed to run Jest encountered an unexpected token... ...SyntaxError: Unexpected token 'export' ...

JavaScript functions with identical names

When attempting to write a function with the same name in both a JS file and on a page, an error was expected but did not occur. Only the function from the JS file executed. This raises the question of how this is possible. Despite separate JS files being ...

Images, CSS files, and JavaScript files in asp.net mvc are experiencing issues with caching

To ensure better security and consistency, I made sure that my pages were not cached. Whenever I pressed the back button on my browser, it always contacted the server to retrieve the HTML content. I accomplished this by implementing a custom action filter ...

Broadcast signals to an overarching frame

I have successfully embedded a chatbot (Angular 14 app) in an iframe and now I need to determine whether the frame should be minimized so it can fit within the parent container. My goal is to send custom events to the receiving frame. let iframeCanvas = do ...

Utilizing WebView for Initiating AJAX Calls

One common question often asked is whether it's possible to make ajax requests using a webview. In my case, the UI will consist entirely of native Android code, but I still need to interact with the backend using ajax calls. Fortunately, I am well-ver ...

How to utilize Node.js to pause execution and wait for a specific function to

In my coding scenario, I am dealing with a specific code snippet that is part of a larger if statement block: message.reply({ embeds: [multipleUsersEmbedFunction("Multiple Users Found", `The following users were found:\n${string}`, members)] ...

A guide on moving Object3D elements using drag-and-drop in three.js

I found a great example of drag and drop functionality using this link. It worked perfectly for individual objects, but now I want to group some elements together to drag and drop them as one unit. To achieve this, I replaced the cubes in the example with ...

The JavaScript code runs first before retrieving any information from the server

When it comes to validating coupons on Stripe, the process needs to be done on the server side rather than the client side. I've tackled this by writing some code for validation, but I'm facing challenges with synchronizing the AJAX/JSON response ...

modify the controller variable and incorporate it into the view using a directive in Angular 1.5

I need to update a controller variable from a child directive, but even after updating the controller variable, the value doesn't change in the view. Should I use $scope.$apply() or $digest? Here is my code: http://plnkr.co/edit/zTKzofwjPfg9eXmgmi8s? ...

What is the best way to combine two arrays using Mongoose?

Group 1 = [X, , , , ,X] Group 2 = [ , , ,O, , ] I am looking for a way to combine group 1 with group 2 in order to achieve the following arrangement: [X, , , O, ,X] without simply replacing Group 1 with Group 2.. Here is the code snippet I have so far: ...

Guide to excluding all subdependencies using webpack-node-externals

My current setup involves using webpack to bundle both server assets and client code by specifying the target property. While this configuration has been working well, I encountered an issue where webpack includes all modules from node_modules even for ser ...

Guide for configuring Quirks mode for Documents in asp.net

Currently, I am using Internet Explorer 10 and I am looking to set the Document mode of the browser to normal Quirks instead of IE 5 quirks for my website. I have tried adding <meta http-equiv="X-UA-Compatible" content="IE=10;IE=9;IE=edge"> in my m ...

Maintain parental visibility with children when navigating to a different page

I am currently working on a vertical accordion menu that opens on hover, stays open, and closes when other items are hovered. The great assistance I received from @JDandChips has been instrumental in getting this feature up and running. Now, my main focus ...

Migration processes encountering delays due to running nodes

When running migrations in Node, I am encountering a timeout error. The specific error message is: Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. Here is the ...

Unitary Individuals and the Connection Automation

It is advised to refrain from using the deprecated com.sun.star.frame.Desktop type and opt for the com.sun.star.frame.theDesktop singleton instead. Various programming languages provide access to singletons. For instance, in Java, this thread mentions the ...

Enhance jQuery for a dynamic navigation dropdown with multiple sub-menus

Looking for help with a jQuery script as I am a beginner in using jQuery. jQuery(document).ready(function ($) { $(".sub-menu").hide(); $(".current_page_item .sub-menu").slideDown(200);; $("li.menu-item").click(function () { if ($('.sub-menu&apos ...