Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Is your <a href="http://weblogs.asp.net/craigshoemaker/archive/2008/09/29/using-jquery-to-call-asp-net-ajax-page-methods.aspx" rel="nofollow">CallPageMethod</a> defined anywhere?</p> <pre><code>function CallPageMethod(methodName, onSuccess, onFail) { var args = ''; var l = arguments.length; if (l &gt; 3) { for (var i = 3; i &lt; l - 1; i += 2) { if (args.length != 0) args += ','; args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"'; } } var loc = window.location.href; loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "default.aspx" : loc; $.ajax({ type: "POST", url: loc + "/" + methodName, data: "{" + args + "}", contentType: "application/json; charset=utf-8", dataType: "json", success: onSuccess, fail: onFail }); } </code></pre> <p>To get the return value of your server-side method, you will need to use the <code>onSuccess</code> callback, not by checking the value of <code>result</code>:</p> <pre><code>function ValidateDelete() { CallPageMethod("IsLangExists", success, fail); } function success(response) { if (response.d) { return confirm('Do you want to continue ?'); } alert('You can not delete this record'); } function fail(response) { //alert("An error occurred."); } </code></pre> <hr> <p>Here's how it should all look together:</p> <pre><code>&lt;script type="text/javascript"&gt; function CallPageMethod(methodName, onSuccess, onFail) { var args = ''; var l = arguments.length; if (l &gt; 3) { for (var i = 3; i &lt; l - 1; i += 2) { if (args.length != 0) args += ','; args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"'; } } var loc = window.location.href; loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "default.aspx" : loc; $.ajax({ type: "POST", url: loc + "/" + methodName, data: "{" + args + "}", contentType: "application/json; charset=utf-8", dataType: "json", success: onSuccess, fail: onFail }); } function ValidateDelete() { CallPageMethod("IsLangExists", success, fail); } function success(response) { if (response.d) { return confirm('Do you want to continue ?'); } alert('You can not delete this record'); } function fail(response) { //alert("An error occurred."); } &lt;/script&gt; &lt;asp:GridView ID="grdList" OnRowCommand="grdList_RowCommand"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="LangId" HeaderText="LangId" Visible="false" /&gt; &lt;asp:TemplateField HeaderText="Delete"&gt; &lt;ItemTemplate&gt; &lt;asp:ImageButton ID="imgBtnDelete" runat="server" CommandName="_Delete" CommandArgument='&lt;%#Eval("LangId")%&gt;' ImageUrl="~/Image/delete_icon.gif" OnClientClick="return ValidateDelete();" ToolTip="Delete" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload