Reputation: 955
I want to send request on server side onFocus
event but my method is not calling, really confused, tried jquery ajax for that but all failed is there any other possible way to send request on server side using asp.net textbox onFocus event?
asp.net website project is created for work.
Ajax method code
$.ajax({
type: "POST",
url: "About.aspx/GetRes",
data: "{}",
contentType: "application/text; charset=utf-8",
dataType: "text",
success: function (msg) {
alert(msg);
}
});
Method which is calling
Public Function GetRes() As String
Return "I am calling GetRes method"
End Function
Upvotes: 0
Views: 696
Reputation: 17724
You can only call PageMethods like that.
Such methods should be static(Shared) and have the WebMethod
attribute.
<WebMethod()>
Public Shared Function GetRes() As String
Return "I am calling GetRes method"
End Function
Upvotes: 2
Reputation: 5989
If you are able to access the supplied url via browser properly then please try this..
$.ajax({
type: "POST",
url: "About.aspx/GetRes",
dataType: "text",
success: function (msg) {
alert(msg);
}
});
Also, i'm considering that your event biding is wrapped under the document.ready callback
and make the server side method like this
<WebMethod>
Public Shared Function GetRes() As String
Return "I am calling GetRes method"
End Function
Upvotes: 2