Discover the best approach for invoking an ASP.NET function from JavaScript when dealing with non-static methods

I'm currently calling an asp.net function from JavaScript using the following code. However, I am trying to call a non-static method and when I remove the static field, the function does not fire. Is there any way to accomplish this? Thank you.

public partial class Test : System.Web.UI.Page
{
   [WebMethod]
   public static string HelloWorld(string name)
   {
       return string.Format("Hi {0}",name);
   }
}


<script type="text/javascript">
function GreetingsFromServer() {
    var name = 'Jalpesh';
    PageMethods.HelloWorld(name,OnSuccess, OnError);
    return false;
}
function OnSuccess(response) {
    alert(response);
}
function OnError(error) {
    alert(error);
}

Answer №1

It is strongly advised against attempting such a feat.

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

Update Material-ui to include an inclusive Datepicker widget

I have integrated the Material-ui Datepicker into my website to allow users to download timed event information from a database. The issue I am facing is that when users select two bracketing dates, events for the end date are not showing up correctly. F ...

JavaScript Reference for the HTML DOM Style's height property and revert back to the initial style height

Hey there! I have a simple fix for those who know JavaScript. I have some code that changes the height style on the first click, but I'm looking for a way to revert back to the original height style on the second click. Here's the code snippet: ...

The selected value is visible on the component, but once it is passed to the server action, it disappears

I am utilizing Nextjs14 and Supabase for my project. Currently, I have a select element where users can make a selection. The selected value is then passed as part of the formValue, which is expected to be received in the server actions as part of the For ...

Tips for eliminating the glowing effect when pressing down on the thumb of the material ui slider

Visit Material-UI documentation for Slider component. Despite setting the disabled flag for the entire slider, the thumb continues to show a halo effect when clicked. ...

Display the names of files depending on the selection made in the drop-down menu

In order to utilize a value from a select box for a PHP function later on the page, I am seeking assistance. Within my index.php file, there is a standard select drop down containing folder names as values and options. After selecting a folder, I aim to e ...

Issue with passing parameter values in MVC Html.ActionLink

Currently, I am experimenting with MVC for a demonstration and have managed to put together some components. However, I am encountering difficulties with an Html.ActionLink. The goal is to display a series of dropdown lists to the user that must be selecte ...

Expand the size of the card box with CSS to create a larger and more prominent display

I recently came across a snippet of Javascript and CSS code. Here is the Javascript: $('.item-card').css("width", $('.item-card').width() + "px"); $('.item-card').css("font-size", $('.item-card').width() * .13 + "p ...

Switch up the box-shadow color with ColorThief!

Is there a way to adjust this script to change the box-shadow color of #player1? <script type="text/javascript> $(window).ready(function(){ var sourceImage = document.getElementById("art"); var colorThief = new ColorThief(); var color = ...

execute the npm start command in the JavaScript file

When I attempt to execute 'npm start' from a file named test.js, I encounter the following error message: (function (exports, require, module, __filename, __dirname) { npm start ^^^^ ...

The alignment of data-table columns appears to be off to the right

Currently, I am working on data-tables and have successfully created one. However, I am facing an issue with aligning the data to the right of some columns. Snippet: var data=[ { "amount": 518212, "billdate": "2018-08-04", "outlet": "JAYA ...

Error: Unable to locate module 'firebase'

import firebase from "firebase"; const firebaseConfig = { apiKey: "AIzaSyCcPSKlYtpdzBoAC8soeSmIARMzVKzrf5I", storageBucket: "challenge-4b2b2.appspot.com", messagingSenderId: "962418448875", ...

Creating a DLL for a Web User Control (.ascx) in ASP.NET - What's the best approach?

I've created a paging control that I want to be able to use in various C# and VB.NET applications. My goal is to bundle everything, including the markup, into a DLL that can be referenced from the bin folders of my other applications. If this approa ...

The customized sweet alert button is failing to trigger its designated function

I integrated vue-swal to show a pop-up dialog with customized functionality. However, I faced an issue while modifying the swal. In my modified version, there are 3 buttons each with specific actions that should be triggered upon clicking. But for some rea ...

Insert the reference to the assembly at the solution level

I manage a collection of solutions consisting of dozens of projects (referred to as proj1 through proj50), each of which relies on the same set of twelve assemblies (known as asm1 through asm12). These assemblies are referenced in the projects without any ...

Manipulate data destination using Javascript

I have a task in my AngularJS application that involves the following steps: 1) Click on a button. 2) If variableA is true, display a modal. 3) If variableA is false, redirect to another link without showing a modal. Here is the code I am using to ...

Tips for defining a relative path in the base URL with AngularJS

Encountering an issue with AngularJS routes related to file paths. The folder structure is as follows: js -> Angular -> css -> Bootstrap -> index.html Routes work fine when hosted on a server like IIS. However, copying and pasting the direct ...

Creating a Configuration File for POST Requests in NodeJS Express

In my NodeJS application using Express, I currently have a hardcoded method for handling URL POST Request Calls and responding with JSON Files. This means that every time I need to add more POST Request Inputs or specify which JSON File to use, I have to m ...

Capturing binary information from a C# ASP.NET HTTP POST Request

Having some trouble with a seemingly trivial task. I am attempting to post binary data to an ASP.NET form as multipart/form-data. The request is being received, and I can confirm this by examining Request.InputStream: -------------------------------7cf2a3 ...

Tips for enlarging small ImageData onto a larger HTML canvas

I am facing an issue with placing image data of size 100x100 onto a canvas of size 1000x1000. Despite my efforts, I have not been able to achieve the desired result. let width=1000; //canvas width let height=1000; //canvas height let img_w=100; ...

"Performing a series of getJSON requests with a delay between each call, iterating through an array

Could someone shed light on why my jQuery/JavaScript code runs with an unexpected flurry of ajax calls instead of at a steady 1-per-second rhythm? var i = 0, l = data.length; function geocode() { $.getJSON( 'https://maps.googleapis.com/maps/api ...