Using Telerik Grid in MVC to access the object that is passed to ClientEvent functions on the Javascript side

Here's a challenging question I have. I'm working with a Telerik Grid that has some ClientSide Events:

.ClientEvents(events => events
    .OnDataBinding("SetAjaxParameter")
)

Within the SetAjaxParameter function, I am setting parameters for ajaxBinding:

function SetAjaxParameter(event) {
    event.data = {
        name: $('#paramterID').val(),
        value: $('#valueID').val()
    };
};

Now, in my controller, I can access the passed parameters 'name' and 'value'. However, I want to call SetAjaxParameter() in JavaScript rather than setting it up in the TelerikGrid configuration. Is there a way to achieve this? I need to obtain the event object passed by the Grid to my function, but I'm struggling to identify what type of object it is and how to retrieve it.

You might be wondering why I want to do this: I aim to separate cshtml and javascript files, with the javascript loading after the html content. As a result, the function for the databinding Event is not yet available.

Answer №1

It turned out to be quite straightforward in the end. All I had to do was include the code snippet below:

    $('#GridName).bind('dataBinding', function (event) {
        SetAjaxParameter(event);
    });

After that, whenever the grid made an AjaxCall, the specified parameter was successfully sent to my controller.

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

What is the destination for next() in Express js?

I'm new to javascript, nodejs, and express, and facing confusion with the usage of next(). I am trying to make my code progress to the next router using next(), but it seems to be moving to the next then instead. This is what my code looks like: // ...

Rotate Text in HTML <thead> Tag

I need assistance with rotating a table header. https://i.stack.imgur.com/hcvxx.png The HTML th elements within the thead section are described as follows: <th> <span class="rotate-all">Period</span> </th> <th> < ...

The equation:() is malfunctioning

Here is a code snippet I'm working with: $("#button").click(function () { for (var i = 0; i < 4; i++) { setTimeout(function () { $(".rows:eq("+i+")").css("background-color", "blue"); ...

Retrieve key codes from inputs sharing the same class

My webpage contains multiple text inputs that all share the same class for various reasons. Currently, I am attempting to capture the ESC button press when an input is focused and alert whether the input has a value or not. However, this functionality on ...

What is the best way to distinguish elements in the same HTML using Angular Material?

Currently, I am working on a project using Angular material, where I have a component.html file that defines a form and a table with data. In the first image of my project, you can see the tab title, a form to add new records, and the table displaying exi ...

Tips for displaying an error message when there is no match found in ng repeat due to filtering

I'm facing an issue with displaying an error message when no match is found after searching in a text box. I've used ng-show to display the message, but it's not working as expected. Can someone assist me with this problem? I am relatively n ...

Unable to successfully perform DELETE or UPDATE operations with Axios MySQL, encountering errors

I am currently working on a project that involves using Axios with Node.Js to perform a delete request in a MySQL table. However, I seem to be encountering an issue as I am not receiving any errors in the console despite having an error catch console.log s ...

Is there a way to control the text animation loop on iTyped, both starting and stopping it?

Currently utilizing React, MUI, along with iTyped The animation implemented involves backspacing text and typing the next word in a specified array until reaching the final word. I am looking to enable a click function on the div containing this animation ...

NavLinkButton - add style when active or selected

I'm working with a list of NavLinks: const users = Array.from(Array(5).keys()).map((key) => ({ id: key, name: `User ${key}`, })); <List> {users.map((user) => { return ( <ListItem disablePadding key={user.id}> ...

Obtain the date in the following format: 2016-01-01T00:00:00.000-00:00

Can someone help me convert this date to the correct format for the mercadolibre api? I need it to be like this: 2016-01-01T00:00:00.000-00:00 However, when I try with the following code: var date_from = new Date(); date_from.setDate(date_from.getDa ...

What is the size restriction when utilizing the "headers" attribute of the jQuery.ajax technique?

What is the size limit for the "headers" property of the jQuery.ajax method? For example: $.ajax({ type: 'POST', url: 'submit.php', headers: { 'CUSTOM_DATA': someBigString },// Is there a limit for "someBigString ...

Updating parent array values within child components in React

Currently, I am working on a React application where I need to save the handlers for all windows opened from the app. Previously, before using React, I stored these windows in a global array attached to the parent window, although I understand that using J ...

Adding an external JavaScript file to an HTML document by importing an array

Having trouble loading an array from an external JS file into my HTML. Snippet from js.js: var temp_max = [4,9,2,5,8,4,2,10]; In the HTML: Note: Be sure to download DateJS and place it in "DATE-JS"!! <!doctype html> <html> ... (HTML c ...

What causes the empty gap to appear during animated transitions between two 'div' elements?

Is there a way to eliminate the white space in between elements during animation? Should I wrap both divs into another div to achieve this? I am using position-top to adjust my div animations. Could this be causing the issue? What other methods can you s ...

Integrating Gatsby.js with my Express server for seamless communication

Currently, I am in the process of developing a basic full-stack application that utilizes Gatsby for the front-end and a simple Express server for the backend. Within my database, there are several users, and my objective is to fetch these users from the b ...

Looking for a speedy solution with a [PHP function] that needs to be converted to a [JavaScript function

Looking for a quick favor - can anyone help me out with this: static function make_url_safe($z){ $z = strtolower($z); $z = preg_replace('/[^a-zA-Z0-9\s] /i', '', $z); $z = str_ireplace(' ', '-', $z) ...

Is there a way to determine if any word within a given text is present in an array?

Imagine you have the following full text: var nation = "Piazza delle Medaglie d'Oro 40121 Bologna Italy" And a given array like: ["Afghanistan", "Italy", "Albania", "United Arab Emirates"] How can we verify if the exact word Italy within that ent ...

Tips for utilizing 'toHaveClass' to find a partial match in Jest?

When I assign the class success to an element, React-Mui appends additional text to it in the DOM, such as mui-AbcXYZ-success. This causes my test using the code snippet below to fail: expect( getByTestId('thirdCheck')).toHaveClass("success ...

Storing information in a JSON file using WordPress AJAX

I've been working on a Wordpress Ajax function that fetches MySQL data as JSON and then logs it. However, instead of displaying the data directly on the page, I want to save it to a JSON file so that I can use it for various purposes. Here is an exam ...

Are there any issues with this Ajax request?

I am currently working on an Ajax call that will submit a form and display different content based on the server's response: $('#applyForm').submit(function(){ var dataString = $(this).serialize(); $.ajax({ type: "POST", url: "php/c ...