invoking a JavaScript function within an if statement

i'm working with two javascript functions

1.

function ValidateGVEducation() {            

        var grid = document.getElementById('<%= gvEducation.ClientID %>');
        var ddlQuali, ddlUni, ddlInsti, ddlAreaS, ddlStat;

        //alert(grid.rows[1].cells[2].getElementsByTagName("*")[0].value);
        if (grid.rows.length > 0) {
            for (var i = 1; i < grid.rows.length; i++) {
                ddlQuali = grid.rows[i].cells[1].getElementsByTagName("*")[0];
                ddlUni = grid.rows[i].cells[2].getElementsByTagName("*")[0];
                ddlInsti = grid.rows[i].cells[3].getElementsByTagName("*")[0];
                ddlAreaS = grid.rows[i].cells[4].getElementsByTagName("*")[0];
                ddlStat = grid.rows[i].cells[6].getElementsByTagName("*")[0];
                if (ddlQuali.options[ddlQuali.selectedIndex].value != "0" ){
                    if (ddlUni.options[ddlUni.selectedIndex].value == "0" || ddlInsti.options[ddlInsti.selectedIndex].value == "0" || ddlAreaS.options[ddlAreaS.selectedIndex].value == "0" || ddlStat.options[ddlStat.selectedIndex].value == "0") {
                        alert('Fill Education Details');
                        return false;
                    }
                }

            }

            return true;
        }
        else return false;
    }

This first function is called within another function

   function validateControlsForSubmit(){
    if (ValidateGVEducation()) {
       alert('Fill Education Details');
       return false;
     }     
    return true;
   }  

In the latter function, it is then invoked in the save button. However, after showing the alert, the ASPX code behind gets executed without the 'return false' statement working properly in this context.

The function call is as follows:

<asp:Button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Save" 
                     onclientclick="return validateControlsForSubmit();"  />

Thank you.

Answer №1

Utilizing jQuery:

<asp:Button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Save" />

$("#<%=btnSave.ClientID%>").on("click", function(event){
    if (ValidateGVEducation()) {
       alert('Please Enter Education Details');
      event.preventDefault();
     } 
});

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

The ReactCSSTransitionGroup does not insert any additional classes

I have been attempting to incorporate animation into each list item within a list of articles that I am loading through an ajax request. Despite my efforts, the ReactCSSTransitionGroup element does not seem to be functioning as expected on the targeted ite ...

I could use some assistance with iterating through an array that is passed as a parameter to a function

Compute the product of parameter b and each element in the array. This code snippet currently only returns 25. This is because element a[0], which is "5", is being multiplied by argument b, which is also "5". The desired output should be ...

Bootstrap 5 alert: The function `$(...).carousel` is not recognized

Despite browsing through numerous similar questions, none of the solutions seem to work for my issue. Listed below are some points I have checked: Jquery is loaded before bootstrap Bootstrap libraries are up to date Confirmation that bootstrap.min. ...

Looking for a unique search object specifically designed for mongodb?

I am currently developing my first application using node.js and angular, and I have encountered a challenge that I am struggling to solve. Let's say I have a User Schema like this: User = { firstname: "Bryan", lastname: "Allan", email: "<a ...

Simulated external prerequisite

//user.js const database = require('database'); exports.createUser = function(req, res){ let user = req.body; if( validateUser(user) ) { database.insertUser(user); //redirect } else { //render new page with the user data ...

The reasons behind the static nature of Ajax pagemethods

What is the reason for Ajax pagemethods being static? ...

Tips for comparing and adding a field to a sub-array within an object

I have a scenario where I have two objects. The first object contains name and id, while the second object has some fields along with the id field from the first object. For Example: FirstObj = [{ _id: '48765465f42424', Name : 'Sample& ...

Ensure the security of a web application utilizing Forms Authentication

I am facing a challenge with a webservice that is protected by form's authentication. The website hosting the service also doubles as a site where users need to log in through a designated login page. Now, I have another website which needs to access ...

Tips for maintaining accessibility to data while concealing input information

Is it possible to access data submitted in a form even if the inputs were hidden by setting their display to none? If not, what approach should be taken to ensure that data can still be sent via form and accessed when the inputs are hidden? ...

IIS requests are stalled - CLR stacktraces not visible in dump file

Running an ASP.NET WebAPI2 application on .NET 4.6.2, hosted on IIS on Windows Server 2016 presents a challenge. Occasionally, numerous requests (hundreds) get stuck for extended periods of time, despite having a request timeout set to 60s with no CPU usag ...

How can I utilize the JQuery GetJSON function to retrieve HTML content from an external webpage?

Imagine you're attempting a jQuery ajax request like this: $.ajax({ ... url: http://other-website.com ... }) You probably know that due to the same-origin policy, this request will fail because the URL is for an external domain. But the ...

AngularJS: intercepting custom 404 errors - handling responses containing URLs

Within my application, I have implemented an interceptor to handle any HTTP response errors. Here is a snippet of how it looks: var response = function(response) { if(response.config.url.indexOf('?page=') > -1) { skipException = true; ...

Attempting to generate a dynamic animation of a bouncing sphere confined within a boundary using components, but encountering

I'm new to JavaScript and currently working on a project involving a bouncing ball inside a canvas. I was able to achieve this before, but now I'm attempting to recreate it using objects. However, despite not encountering any errors, the animatio ...

The presence of Vue refs is evident, though accessing refs[key] results in an

I am facing an issue with dynamically rendered checkboxes through a v-for loop. I have set the reference equal to a checkbox-specific id, but when I try to access this reference[id] in mounted(), it returns undefined. Here is the code snippet: let id = t ...

Sending parameters to ajax using a click event

I'm facing an issue with passing variables through Ajax to PHP. In a PHP file, I'm generating some divs with id and name attributes. livesrc.php echo "<div class=\"search-results\" id=\"" . $softwareArray['Sw_idn'] ...

How to trigger a function in a separate component (Comp2) from the HTML of Comp1 using Angular 2

--- Component 1--------------- <div> <li><a href="#" (click)="getFactsCount()"> Instance 2 </a></li> However, the getFactsCount() function is located in another component. I am considering utilizing @output/emitter or some o ...

The function RenderItems is being referenced but is not defined within the return statement, causing

Hey everyone, I'm relatively new to ReactJS and I'm currently working on getting response data objects to display on a web app without users having to inspect the page or check the network/console for file upload error responses with the name &ap ...

Load a page and sprinkle some contents with a slide effect

I am brand new to jQuery and just starting out, so please excuse me if this question seems basic or silly. I would like the header and footer of my page to stay in place while the center content slides in from the right side when the page loads. This websi ...

What is the process for sending a JSON response and then redirecting to an HTML page after a successful event in Node.js using Express?

Trying to send a JSON response and redirect the page simultaneously in Express.js. Need help figuring out how to achieve this. Is it possible to redirect in Express.js while sending a JSON response to the client? The goal is to use this JSON data to render ...

The TypeScript declaration for `gapi.client.storage` is being overlooked

When I call gapi.client.storage.buckets.list(), TypeScript gives me an error saying "Property 'storage' does not exist on type 'typeof client'." This issue is occurring within a Vue.js application where I am utilizing the GAPI library. ...