Hi All ,
how to pass the textbox value in webmethod in codebehind through ajax call method.
sample method :
$(function () {
// var stDt = $("#txtStartDt").val();
$.ajax({
type: "POST",
url: "InteractiveDashboard.aspx/Web_GetTotalSaleslist",
data: "{'StartDate':'" + stDt + "','EndDate':'" + EndDt + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
//alert(response.d);
alert("Error..1");
},
error: function (response) {
alert("Error..2");
alert(response);
}
});
});

Amit MohantyPosted May 23, 2024, 8:11 AM
Try like this:
Abhishek ChadhaPosted May 23, 2024, 8:11 AM
you can follow the below steps:
Create a Web Method in Code-Behind:
YourPage.aspx.csfor Web Forms or a controller for MVC), create a static method and decorate it with the[WebMethod]attribute.Call the Web Method using AJAX:
Retrieve and Process the Value in the Web Method:
This way, when the "Call Web Method" button is clicked, the textbox value will be sent to the web method through an AJAX call, and the response from the web method will be displayed in an alert box