The Asp.net OnClick event seems to lose functionality when an excessive number of ajax calls are made

Currently, I'm working on a dashboard project and utilizing gridStack for the layout. As part of this process, I am updating the database using ajax to store the x and y positions of various HTML elements (specifically divs on the page). Below is the JavaScript code snippet that handles this functionality:

// The "dragstop" function is triggered when dragging of the div element stops.

$(".grid-stack").on("dragstop", function () {
    setTimeout(function () {
        saveAllWidgets();
    }, 100);
});


function saveAllWidgets() {
    var serializedData = _.map($('.grid-stack > .grid-stack-item:visible'), function (el) {
        el = $(el);
        var id = el.attr('id');
        var node = el.data('_gridstack_node');
        return {
            x: node.x,
            y: node.y,
            width: node.width,
            height: node.height,
            id: id
        };
    });

    var jsonString = JSON.stringify(serializedData);
    try {
        $.ajax({
            type: "POST",
            url: '/STARCOHttpHandlers/UpdateDashboardWidget.ashx',
            contentType: "application/json; charset=utf-8",
            data: jsonString,
            dataType: "json",
            success: function(data){
                console.log(data); 
            },                 
            error: function(){
                console.log("An error occurred, database was not updated!!");
            }
        });
    } catch (e) {
        alert(e);
    }
}

The issue I am encountering is that if the above function is called too frequently due to excessive drag-and-drop actions, and then I click on an ASP.NET button mentioned below, the page refreshes but the OnClick event is not triggered (even in debug mode where the code does not get executed at all). Only after refreshing the page and clicking on the button a second time does the OnClick event trigger properly.

<asp:Button runat="server" ID="btnUndoChanges" CssClass="btn" Text="Undo all changes" OnClick="btnUndoChanges_OnClick"/>

 protected void btnUndoChanges_OnClick(object sender, EventArgs e)
        {

            return;
        }

I am unsure why this behavior is occurring. Is it possibly related to IIS security settings or the viewstate?

Answer №1

Upon investigating for 48 hours, I finally discovered that the issue stemmed from the ViewState. Sharing this solution in hopes that it may benefit others utilizing GridStack.JS:

Incorporated the specified code snippet below to successfully resolve the issue.

protected override void OnInit(EventArgs e)
{
    Page.ViewStateMode = ViewStateMode.Disabled;
}

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

Encountering a problem sending an array of objects to a controller via jQuery AJAX

I attempted to send an array of objects to a controller using jQuery Ajax, but I am getting a null result in ASP.NET 5.0. The data array that I'm sending is named regions. The constructor for the data is defined in the BoundingBoxModel class. Here i ...

Learn how to simultaneously play two audio files using the same identifier in JavaScript

I'm facing an issue with two audio files that have a progress bar and both have the same ID: <audio id="player" src="<?=base_url('mp3/'.$rec->file)?>"></audio> </p> ...

Javascript - Button animation malfunctioning after first click

One issue I'm facing is with an animation that is triggered using the onmousedown event. Another function is supposed to stop the animation when onmouseup is detected. The problem arises after the first time it works correctly. Subsequent attempts to ...

What is the best method for installing a package specified as a peerDependency?

I'm in the process of creating a library and I'm looking to figure out how to specify and install a dependency under peerDependencies. I couldn't find any information about this in the npm documentation when using the command npm install: ...

Process running on an undetermined outcome (resulting from a function that requires promises to be fulfilled)

I'm feeling pretty lost when it comes to handling promises. I've been doing a lot of reading, particularly in the context of Typescript and Angular, as I'm working on fetching data from an API REST. Within my code, there's a method call ...

Using both jQuery and Ajax can result in multiple requests being sent when utilizing the focus

Hey there, I've got a form with around 20 input fields. My goal is to trigger an AJAX request every time a user moves from one field to another. Everything seems to be working fine, but there's a peculiar issue. Upon moving from one field to th ...

Launching an embedded webpage in a separate tab within the main browser window

In my current setup, I have implemented an iframe within the main window. The iframe includes a form where users can input data and submit it. Currently, I achieve the submission with the following code: var openURL = '/results/finalpage'; windo ...

Tips for avoiding identical selections in multiple drop-down menus within a table and sending the data to the server via a POST request

For instance: visualizing a chart of infants, where each row the user chooses baby GenderDropDown, then picks a name. It's crucial to prevent duplicate name selections throughout the chart. If a user selects Male & John, that choice should not be ...

Looking to display user data within a specific div using JavaScript? Check out my code!

Issue Solved by Me I resolved the problem by using ko.js to check data binding in java! Thanks to everyone who helped. I have implemented this code to display online users in my chat application (x7chat 3, available for free download) The code can be fou ...

Developing a Quarantine Simulation Prototype Using JavaScript

I am in need of a method to determine if any passengers are not healthy. If "isHealthy" is false for any passenger, then the wagon should be quarantined. Additionally, there may be an issue with the join prototype where "isHealthy" is only triggered if a ...

Show a specific row in a table with an option to make updates by utilizing JQuery Ajax

I am trying to fetch row contents in order to display them in a form for updating using jQuery AJAX, but I'm running into some issues. Could someone assist me with this? It's really important for me to understand how to do it properly. When I ex ...

Updating serialized $_POST array with new key/value pair using jQuery AJAX

Is there a way to insert additional values into a serialized $_POST array before sending an AJAX request using jQuery? Here's the situation: $('#ajax-preview').on('click', function(e) { e.preventDefault(); var formData = ...

What could be causing the directives module to not get properly incorporated into the Angular app module?

I am currently in the process of learning Angular and have come across some challenges with module resolution. In js/directives/directives.js, I have a directive scoped within a directives module: angular.module("directives").directive("selectList", funct ...

Check an array of objects for duplicate key-value pairs by cross-referencing other key-value pairs within the array using JavaScript

let selectedFruit = "mango" let fruitArray = [{fruit:"apple",locale:"US"}, {fruit:"orange",locale:"US"}, {fruit:"banana",locale:"US"}, {fruit:"apple",locale:"US"}, {fruit:"orange",locale:"IT"}, {fruit:"apple",locale: ...

Enabling Event bus suggestions for Typescript: A step-by-step guide

Hello, I've encountered an issue while attempting to add types for the TinyEmitter library. Specifically, I need to define two methods. First: addEventListener(e: string, (...args: any[]) => void): void; Second: emit(e: string, ...args: any[]): vo ...

Prevent screen from loading without JavaScript using an overlay

Is there a way to darken and lock the page, preventing clicking or scrolling, while displaying white text notifying the user that JavaScript is not enabled? I understand that the recommended approach is to gracefully degrade all elements when JavaScript i ...

What is the process for creating a personalized aspx page?

I have a burning question about learning to develop custom ASPX pages. For example, if you create an ASPX page automatically, the following code is generated: using System; using System.Collections.Generic; using System.Linq; using System.Web.UI; using S ...

Identifying iOS Opera Mini browsers using JavaScript

Is there a way to prevent a specific script from running on the IOS Opera Mini browser? The navigator.UserAgent method is not providing clear identification for this browser. The returned string looks something like this: Mozilla/5.0 (iPhone; CPU iPhone O ...

AWS - lambda is unable to assume the defined role for the function due to restrictions

As a beginner with AWS CDK, I encountered an issue while setting up my Lambda function. Here is the code snippet: import { ManagedPolicy, Role, Group, User } from 'aws-cdk-lib/aws-iam'; import { NodejsFunction } from 'aws-cdk-lib/aws-lambda- ...

Retrieve data from the database and insert it into a newly created row dynamically

I am a beginner in the world of PHP programming. Currently, I am working on creating a billing system program. I have successfully created a table and added rows to it dynamically. Now, my next challenge is to add values from a database to these dynamicall ...