$("#btnSsearch").click(function () {
if ($.trim($("#txtSearch").val()).length == 0) {
$("#message").html("Please enter something for me to search.");
return;
}
else {
$("#searchResults").jqGrid({
url: "Default.aspx/SearchProducts", // <-- public static string SearchProducts(string keywords)
postData: { keywords: 'ipad' }, // <--- Is this how to pass in the parameter?
mtype: "POST",
ajaxGridOptions:{ contentType: "application/json; charset=utf-8"},
datatype: "json",
colNames: ['ID', 'ProductName'],
colModel: [
{name: 'ID', index: 'ID', width: 100},
{ name: 'ProductName', index: 'ProductName', width: 100 }
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager',
sortname: 'ID',
viewrecords: true,
gridview: true,
sortorder: "asc",
caption: "search results"
}).navGrid("#pager", { edit: false, add: false, del: false });
}
});
That's what I have been trying. However, the server side webmethod SearchProducts(string keywords) never gets hit.
BUT, if I use $.ajax({ .... }) to post to the same webmethod, I do get the data back correctly. So, something must be wrong with the way I call my server side web method in jqGrid. Yet, my hours' of search online didn't
solve the problem. First of all, a lot of examples are in php, which are only minimally helpful. Second of all, most of the examples are dummy, they don't tell me how to pass parameters to my web method inside jqGrid.
Any WORKING example using jqGrid, calling a C# web method which takes parameters? Thanks.
First hit the F12 for developer tools and check if you see any javascript errors in the console section..?
If you see errors then see what the errors are. Then try removing the postdata parameters and pass it as a Query String and see if you see the same error again...
First hit the F12 for developer tools and check if you see any javascript errors in the console section..?
If you see errors then see what the errors are. Then try removing the postdata parameters and pass it as a Query String and see if you see the same error again...
url: "Default.aspx/SearchProducts?keywords=ipad",
Thanks, I did try passing the parameter through the query string like you suggested, but it didn't help. After I pressed F12, I did see the javascript console, but how do I know if an error exists? Are you saying the console will tell me? If that's the
case, I haven't seen anything wrong.
You see red text in your console if there is an error with your javascript. Then if this does not help hit the Network tab in the console and check if there is a post request as soon as you click the button...
Also where are you specifying the Button Click event ..
$("#btnSsearch").click(function () {
Make sure your code is in your document.Ready event. Otherwise your event will not fire... To be sure that your event is working place an alert in the Button Click event and check if you see the alert. Also replace your click method like this
antonyliu200...
Member
168 Points
310 Posts
jqGrid does not post to the URL
May 30, 2012 07:47 PM|LINK
$("#btnSsearch").click(function () { if ($.trim($("#txtSearch").val()).length == 0) { $("#message").html("Please enter something for me to search."); return; } else { $("#searchResults").jqGrid({ url: "Default.aspx/SearchProducts", // <-- public static string SearchProducts(string keywords) postData: { keywords: 'ipad' }, // <--- Is this how to pass in the parameter? mtype: "POST", ajaxGridOptions:{ contentType: "application/json; charset=utf-8"}, datatype: "json", colNames: ['ID', 'ProductName'], colModel: [ {name: 'ID', index: 'ID', width: 100}, { name: 'ProductName', index: 'ProductName', width: 100 } ], rowNum: 10, rowList: [10, 20, 30], pager: '#pager', sortname: 'ID', viewrecords: true, gridview: true, sortorder: "asc", caption: "search results" }).navGrid("#pager", { edit: false, add: false, del: false }); } });That's what I have been trying. However, the server side webmethod SearchProducts(string keywords) never gets hit.
BUT, if I use $.ajax({ .... }) to post to the same webmethod, I do get the data back correctly. So, something must be wrong with the way I call my server side web method in jqGrid. Yet, my hours' of search online didn't solve the problem. First of all, a lot of examples are in php, which are only minimally helpful. Second of all, most of the examples are dummy, they don't tell me how to pass parameters to my web method inside jqGrid.
Any WORKING example using jqGrid, calling a C# web method which takes parameters? Thanks.
sushanth009
Contributor
6243 Points
1168 Posts
Re: jqGrid does not post to the URL
May 30, 2012 08:15 PM|LINK
First hit the F12 for developer tools and check if you see any javascript errors in the console section..?
If you see errors then see what the errors are. Then try removing the postdata parameters and pass it as a Query String and see if you see the same error again...
antonyliu200...
Member
168 Points
310 Posts
Re: jqGrid does not post to the URL
May 31, 2012 01:55 PM|LINK
Thanks, I did try passing the parameter through the query string like you suggested, but it didn't help. After I pressed F12, I did see the javascript console, but how do I know if an error exists? Are you saying the console will tell me? If that's the case, I haven't seen anything wrong.
sushanth009
Contributor
6243 Points
1168 Posts
Re: jqGrid does not post to the URL
May 31, 2012 03:21 PM|LINK
You see red text in your console if there is an error with your javascript. Then if this does not help hit the Network tab in the console and check if there is a post request as soon as you click the button...
Also where are you specifying the Button Click event ..
$("#btnSsearch").click(function () {Make sure your code is in your document.Ready event. Otherwise your event will not fire... To be sure that your event is working place an alert in the Button Click event and check if you see the alert. Also replace your click method like this
$("#btnSsearch").on('click' , function () {elodie1979
Member
96 Points
106 Posts
Re: jqGrid does not post to the URL
Jul 03, 2012 06:31 PM|LINK
Hi, Did you ever resolve this issue?
I am having similar problems calling a c# web method in jqGrid and can't find any examples or help regarding this.
sushanth009
Contributor
6243 Points
1168 Posts
Re: jqGrid does not post to the URL
Jul 03, 2012 09:59 PM|LINK
For more help you can check this out.
It's better if you post your question here http://forum.jquery.com/using-jquery-plugins which are dedicated to using jQuery plugins..
antonyliu200...
Member
168 Points
310 Posts
Re: jqGrid does not post to the URL
Jul 04, 2012 04:47 AM|LINK
If you know that path to /YourController/YourActionMethod exists, but jqGrid doesn't post to it, check your routing rule.
pon_prabhu
Participant
828 Points
185 Posts
Re: jqGrid does not post to the URL
Jul 04, 2012 06:38 AM|LINK
Make sure you have added these too. (as in Order)
~/Scripts/grid.locale-en.js
~/Scripts/jqgrid.js
hafizzeeshan
Participant
834 Points
253 Posts
Re: jqGrid does not post to the URL
Jul 04, 2012 07:29 AM|LINK
HI
1) Plz check the even is called ?
2) plz check in page souce the id of "#searchResults" , if it is not same then plz convert into .ClientID
3) if u r not working in MVC , URL is also wrong.
4) Check the Following Code
$(function() {
var intCompanyId = document.getElementById('<%= lblCompanyId.ClientID %>').innerHTML;
$("#ManageSubjectGrid").jqGrid({
url: 'SubjectManagement.ashx?CompanyId=' + intCompanyId,
datatype: 'json',
height: 320,
colNames: ['Subject Name','Abrivation','Creation Date','Modified Date','Action'],
colModel: [
{ name: 'varName', width: 110, sortable: false },
{ name: 'Abrivation', width: 140, sortable: true },
{ name: 'dtCreationDate', width: 130, sortable: true },
{ name: 'dtModificationDate', width: 120, sortable: true },
{ name: 'intSeqId',index: 'intSeqId', width: 110, sortable: true,editable: true }
],
rowNum: 25,
rowList: [25, 50, 100,250,500],
mtype: "POST",
pager: '#ManageSubjectGridPager',
sortname: 'varName',
viewrecords: true,
sortorder: 'asc',
caption: 'Manage Subject',
footerrow: false, userDataOnFooter: false
});
$("#ManageSubjectGrid").jqGrid('navGrid', '#ManageSubjectGridPager', { edit: false, add: false, del: false,search:false });
});
Regards
Zeeshan
Zeeshan Rauf
# 92-3216698206
Email : zeeshan_rouf@hotmail.com
Please mark the replies as answers if they help or unmark if not.