Reputation: 1620
I have the following JQuery in my aspx page to call the Code behind function
onDelete: function (item) {
//Some Code
$.ajax({
type: "POST",
url: 'Page_Name.aspx/callmethod',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
}
I am calling the below Method
[WebMethod]
public static void callmethod()
{
Page_Name call = new Page_Name();
call.Function();
call.Function_Structure();
call.Function_items_Structure();
call.OClear();
call.PClear();
call.IClear();
}
I had tried in many ways but its not working kindly any one point me what could be wrong here
Upvotes: 0
Views: 2281
Reputation: 4069
Try using {}
for your data, "{}"
will be considered as string or don't include data parameter if you are not sending any parameters.
onDelete: function (item) {
//Some Code
$.ajax({
type: "POST",
url: 'Page_Name.aspx/callmethod',
// data: "{}",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json"
});
}
Upvotes: 2
Reputation: 13833
What you are trying to accomplish is inherently impossible. In your webmethod, I see the following lines:
call.pnlCH.Visible = false;
call.pnlPdtl.Visible = false;
You're trying to change the attributes of your ASP.Net form elements, but without using a postback operation. If you do not have a postback, ASP.Net will not re-render your page for you! It will only return what you tell the webmethod to return, which in your case is void
.
There are two ways to fix this, I'm not sure which it is you want:
Option 1 - No ASP.Net interference needed
If you only want to change some element's visibility, you could do that via jQuery, you don't need your backend for that.
$("#myElement").show();
$("#myElement").hide();
For ASP.Net controls, you'll want to know the clientId.
var clientId = <%= pnlCH.ClientID %>;
$("#" + clientID).hide();
Option 2 - ASP.Net is needed
If you need your backend code for this (e.g. to look something up from the database, or any other good reason), doing it purely via jQuery isn't going to help. In this case, what you'll want to be doing is perform a regular postback scenario.
Having the page post back means that ASP.Net will render your page again. Any change you make to the form elements will then be rendered.
It's important to note here that a postback is required to have ASP.Net re-render your page.
So all in all, I'm not sure which way you want/need to go with this. But your current approach, while syntactically valid, will simply not work because of how ASP.Net and client-side asynchronous calls work.
Upvotes: 2
Reputation: 22884
Try adding an error function to your $ajax call, and see what errors come back.
data: {},
dataType: "json",
error: function(jqXHR, textStatus, errorThrown ) {
// debug here
alert(jqXHR);
},
success: function() ...
Upvotes: 0