The PageMethods function is successful when using a single parameter, but encounters an error when attempting to use two parameters, resulting in the

PageMethods worked perfectly when sending a single parameter to a code-behind aspx page. However, I encountered the error "Unknown web method" when attempting to provide two parameters (or an Object other than a String).

The functional code in my aspx page is:

<asp:ScriptManager ID="smAjax" runat="server" EnablePageMethods="true"> </asp:ScriptManager> 

and in a js file included:

function AjaxSuccess(results) {
    alert("AjaxSuccess: " + results);
}
$(document).ready(function () {
    PageMethods.TestAjaxCall("value 1",  AjaxSuccess);
}

and in the code-behind:

<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
<WebMethod> _
Public Shared Function TestAjaxCall(ByVal item1 As String) As String
    Return item1
End Function

However, making the following adjustments resulted in an exception (System.ArgumentException: Unknown web method TestAjaxCall.): and in an included js file:

function AjaxSuccess(results) {
    alert("AjaxSuccess: " + results);
}
$(document).ready(function () {
    PageMethods.TestAjaxCall("value 1", "value 2", AjaxSuccess);
}

with the corresponding modification in the code-behind:

<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
<WebMethod> _
Public Shared Function TestAjaxCall(ByVal item1 As String, ByVal item2 As String) As String
    Return item1 & ": " & item2
End Function

Answer №1

After deleting the <ScriptMethod> element, the issue was resolved:

<WebMethod> _
Public Shared Function AjaxTest(ByVal data1 As String, ByVal data2 As String) As String
    Return data1 & ": " & data2
End Function

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

Troubleshooting: Vue.js custom select element not responding to blur event

Unique Scenario A custom autocomplete select component has been created that not only autocompletes but also allows for adding a new value if the result is not found. This functionality was discovered to be missing in the vue-select module. Explore the C ...

Strategies for managing events within functional React components without relying on mutative operations

Based on insights from Cam Jackson, the recommendation is to utilize Redux and create small, stateless functional components. For example: const ListView = ({items}) => ( <ul> {items.map(item => <ItemView item={item}/>)} ...

Retrieving game information from the Hearthstone API

I'm currently working on developing a random Hearthstone card generator, but I've run into some issues with extracting JSON data from the API and converting it into a JavaScript object for use in my HTML. While I've confirmed that the API re ...

What steps can I take to address the problem of my undefined .length value?

I encountered a length error while executing line 2 in this code snippet. index.js:10 Uncaught TypeError: Cannot read property 'length' of undefined" Sample Code: <div class="formCustomerName"> <label>Name:</label> ...

Key steps for effectively implementing a Substring-Filter on a JSON array in d3

Trying to apply filtering on a JSON data array structured like this: var data = [ { "key": "FirstGroup", "color": "#1f77b4", "values": [ { "label ...

Access a webpage whose URL has been dynamically assigned using JavaScript

I have a website that consists of a single page and features four tabs. Whenever a tab is clicked, it displays the corresponding content in a div while hiding the other three divs along with their respective content. To ensure a smooth user experience, I u ...

Ensuring proper alignment within anchor links and buttons

button, a { height: 30px; display: inline-block; border: 1px solid black; vertical-align: middle; } button > div, a > div { width: 30px; height: 10px; background-color: red; } <button> <div class="buttonDiv"></div> ...

How can I use JavaScript to show a div upon clicking an input element?

I am looking to make a block div visible when an input field is clicked. <input class="indifferent" type="radio" name="decision" value="indifferent"> Indifferent </br> <div class="input" style="display: none;"> Please assist with our com ...

What impact does turning off Javascript have on ASP.NET?

There seems to be varying accounts of the impact of turning off JavaScript on ASP.NET applications. Some say it works fine, others claim only certain parts are affected, while some suggest that nothing functions at all. I am curious to know specifically h ...

What is the method for shifting the expansion panel icon position to the left?

I need the expansion arrow in my app to be on the left side of the panel. However, it currently appears on the right side by default. This is what I have tried: <ExpansionPanelSummary className={classes.panelSummary} expandIcon={<ExpandMore ...

How come my Bootstrap tooltip title only updates once when I use the keydown event in jQuery?

My goal is to provide users with a character count for text inputs and textareas based on a maximum limit. To achieve this, I have added tooltips to elements with a data-maxlength attribute. I update the tooltip for text inputs to display the current lengt ...

Service in Angular JS dispatching coordinates to controller

I am in need of retrieving a path consisting of latitude and longitudes for displaying on a map within my app. To handle all the API calls, I have set up a basic controller. function mainController($scope, $http){ $http.get('/api/lastrun') ...

PHP loaded HTML does not allow JavaScript to execute

My system includes an announcements feature where all announcements are retrieved from a database and displayed on the screen using Ajax and PHP. Below is the code snippet used to load each announcement onto the page: echo '<div id="announcements ...

Uncovering the inherent worth of an item pulled from a remote location using Vue.js

Currently, I am retrieving a list of countries by making an API call in VueX. The fetched data is then stored in a state using a mutation. Essentially, the countries are saved in a variable known as this.$state.getters.countryList, which can be accessed f ...

When using the dict update method in SQLAlchemy, how does it affect the Object-Relational Mapping (ORM

Recently, I encountered an issue with a SQLAlchemy Table that had a JSON column: from sqlalchemy.dialects.postgresql import JSON class MyTable(db.Model): id = db.Column(db.Integer, primary_key=True) my_json_column = db.Column(JSON) My attempt to ...

Insert DOM elements at the start of the parent element

I'm currently using the following JavaScript code to insert AJAX responses into a div with an ID of results: document.getElementById("results").innerHTML=xmlhttp.responseText; The issue I am encountering is that this code adds all new elements after ...

Adjusting the view to focus solely on the visible portion of the webpage

Is there a way to achieve zooming in and out on a website similar to how it works on the site ? I want only the visible area to zoom in or out when users interact with their browser. I searched online for a solution but couldn't find one. Any suggesti ...

What is the best method for utilizing dynamically assigned keys within a JSON object?

I am currently working with Rhino and I need to find a way to utilize a variable in order to define the key of a map. Here's an example of what I'm trying to achieve: var name = "Ryan"; var relationshipType = "brother"; var relatedName = "David" ...

Attempting to store the output of a function in a variable

My current script is designed to verify if the value of a selected element matches the span id. While the function itself functions correctly (verifying object.id via alert), I am encountering issues with variable assignment. When attempting to alert the ...

What is the best way to store chat messages in a React application?

My idea for a chat application using React involves saving chat messages in localStorage. Below is the code snippet that illustrates this functionality: const [textMessages, setTextMessages] = useState([]); const [textValue, setTextValue] = useState(' ...