Utilizing JavaScript to Trigger a Function from Code Behind

Having trouble calling a function through javascript and receiving an error message "CS0103: The name 'bidindex' does not exist in the current context". Can anyone provide assistance? Thank you!

JavaScript code snippet:

<script>
    function senddata(whatdate, bidindex) {          
        var a = "<%=DatabidGridView1(bidindex,whatdate%>";
    }
</script>

C# code snippet:

public string DatabidGridView1(string sindex, string sdate)
        {
   return "good";
        }

Answer №1

In agreement with homungus, it is crucial that the Method in your codebehind must be a static WebMethod.

Here's an example:

JavaScript Code

$(".clickMe").click(function(){ sendData(data, index) });

function sendData(whatData, bidIndex) {          
   PageMethods.DataBidGridView1(bidIndex, whatData);
}

.CS Code

[WebMethod]
public string DataBidGridView1(string sIndex, string sDate)
{return "good";}

For more useful information, you can check out this link: Pagemethods in asp.net

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

Tips for utilizing the TinyMCE special button and personalized dialog box for inserting content into your website

By utilizing the TinyMCE editor, I successfully added a custom button to its toolbar and connected it to a Flickr account. This allows a specialized dialog box to display with various image options. The goal is for users to click on an image within the di ...

5 Bootstrap Popovers with Custom HTML Contents

I am having trouble separating the content of the bootstrap5 popover from the HTML attributes, unlike other components where it is achievable. var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')) var ...

ASP.NET Core: Enhancing performance with asynchronous services

I have developed an ASP.NET core application that utilizes a service layer to interface between my controllers and Entity Framework. Currently, my services operate synchronously, but I am interested in transitioning them to utilize asynchronous methods. ...

Retrieving the real server response using Angular's $resource

I have developed an API using Laravel which provides JSON data in the following format: { "data":{ "errors":{ "username":"The username you entered has already been taken.", "email":"The email address provided is already in use." } ...

The debate between ensuring input validity and making fields mandatory on multi-page forms

I am currently working on a multi-page form and using jQuery Validate to validate it. The user has four options: next, prev, save, submit. Save, next, and prev all save the current page within the form; whereas submit is similar to save, but triggers addi ...

Increase the size of the Bootstrap select input area to exceed the dimensions of

Is there a way to ensure that the selection area of my bootstrap select is not larger than its parent container on small screens (mobile)? My issue can be seen in the image below and is recreated in the snippet provided. The black bar represents the edge ...

Properly setting up a personalized input component in Angular 6

After attempting to create a custom input component with debounce functionality, I decided to follow the advice provided in this helpful suggestion. Although the debounce feature is working, I encountered an issue where the initial value of the input comp ...

Is there a way to modify the title of a website upon entering the webpage and then updating it when moving to a new page?

I'm encountering an issue with changing the website title during two specific processes. Upon entering a webpage, the title is modified using the following code: <script type="text/javascript"> $(document).ready(function() { docum ...

Struggling to design a functional mobile keyboard

I've been working on creating a mobile keyboard, but I'm facing some issues with the JavaScript part. The problem seems to be in my code as the keyboard isn't responding when I try to type. Here's a snippet of the JavaScript I'm us ...

Is there a way to make all Bootstrap column heights equal using only jQuery?

I am currently working on matching the heights of two columns without using an existing library like match-height.js. In this specific case, I have a row with 2 columns where the first column contains a centered black square and the second column contains ...

Managing Alert and Confirmation Pop-ups Using JavascriptExecutor in Selenium with GhostDriver

In my current project, I am facing a challenge. I am utilizing Selenium 2.42.2 along with the phantomjsDriver 1.1.0 in Eclipse using Java. It is crucial for my test to be able to identify and save messages from Alerts, Confirms, and possibly Prompts when a ...

Tips for sending multiple object data in JSON format through a web API using a single controller

Here is an example of JSON data: { "datetime": "2019-07-31 15:40:01", "Kursi": [ { "kursi_id": 23, "kursi_value": 100 } ], "Bunga": [ { "bunga_id": 3, "bunga_value": " ...

How can you transform a string into an array using JavaScript?

Looking to transform a string into an array using javascript? var strng = "[x,y]" The desired result should be: var arry = ["x","y"] ...

"Exploring the Power of Node.js and Firebase for

I'm encountering some issues with Node.js, as I am fairly new to it. I am attempting to create a post method, but it keeps returning Something is not right and I'm struggling to identify the problem Here is the code snippet. exports.createN ...

Issue with Angular: Problems with script references

I am currently working on a small Angular app for a school project, and I'm running into an issue where my script is not being imported correctly (it displays '{{1+1}}'). Both the index.html and app.js files are located in the same folder. ...

Display the value of my JavaScript variable within a div element

I am having trouble displaying the JavaScript variable "dayz" in the results div. When I try to use alert(dayz) after the calculation, it works fine, but I need it to output the dayz variable in the HTML. Can anyone help me with this issue? <html> ...

Issue encountered when sending XML data to .NET web service using ASMX technology

I am facing an issue where the XML constructed data is not being successfully posted to the webservice .asmx file. Despite making an AJAX call, the control does not seem to transfer to the webservice file. Could there be a syntax problem in the AJAX call? ...

When an href is clicked in an HTML table, I am interested in fetching the value of the first column row

When a user clicks on the "Edit" link in each row, I want to display an alert with the value of the first column in that row. For example, if I click on the "Edit" link in the first row, I should see an alert with the value of the first column in that row. ...

Loading 3D models in Three.js from the cache

Every time my page reloads, the loader loads objects from the URL instead of cache. Is there a way to check if the resource is in cache and load it directly? Appreciate your help! ...

Emulate mobile view using Javascript and HTML simulation tool

I am trying to simulate the appearance of a website on a mobile phone. For example, consider the following code: <div> <div class = "col-md-6 col-sm-6 col-xs-12"> First </div> <div class = "col-md-6 col-sm-6 col-xs- ...