I have two textboxes and submit button. I validate aspneForm using Jquery. The problem is that after validation serverice side code(i.e button_click event) not firing.
But the problem is that we have to make MyMehtod as Static otherwise it will not be Call and for this all controls on form must be static which is I think not a good solution.
Take HTTPHandler, define your method in that as public and call it from Process_request method or put all your logic in process_request method instead of "MyMethod".
Call httphandler instead of "Page.aspx". it will work same. You need not to define it as static method in hadler.
Regards,
Shailesh
If This post helps you to solve your problem please mark this as an answer.
page methods are an ajax callback. when you call a page method, the form data is not processed nor is the page life cycle run. it just a shortcut to build a web service.
also in your sample ajax call, no data is passed to the page method anyway.
I have solved using following logic in my page_load event.Please inform me if this process has any drawback(s): I asume that when call from javascript then Request.HttpMethod will be "POST"
JavedBoqo
Member
145 Points
144 Posts
Ajax Submit Issue
Dec 27, 2011 02:27 PM|LINK
Hi,
I have two textboxes and submit button. I validate aspneForm using Jquery. The problem is that after validation serverice side code(i.e button_click event) not firing.
sivilian
Contributor
6235 Points
1194 Posts
Re: Ajax Submit Issue
Dec 27, 2011 04:06 PM|LINK
Is the page not posting back at all? Check if you have a return false at the end of your jquery validation. This will stop the postback.
hope this helps,
sivilian
JavedBoqo
Member
145 Points
144 Posts
Re: Ajax Submit Issue
Dec 27, 2011 04:18 PM|LINK
no i have't return false
shailesh son...
Contributor
2273 Points
495 Posts
Re: Ajax Submit Issue
Dec 28, 2011 09:19 AM|LINK
Hi,
You need to bind the onclick event handler.
Refer following links:
http://stackoverflow.com/questions/716827/jquery-click-event-on-aspbutton
http://stackoverflow.com/questions/855747/jquery-asp-net-button-click-event-via-ajax
Shailesh
If This post helps you to solve your problem please mark this as an answer.
SharePoint 2010:
http://weblogs.asp.net/shailesh/archive/2010/07/07/sharepoint-2010-introduction-to-client-object-model.aspx
nilsan
All-Star
17526 Points
3823 Posts
Re: Ajax Submit Issue
Dec 28, 2011 09:25 AM|LINK
Could you show us what have you done?
Blog | Get your forum question answered | Microsoft Community Contributor 2011
JavedBoqo
Member
145 Points
144 Posts
Re: Ajax Submit Issue
Jan 02, 2012 12:21 PM|LINK
When my form validation completed(using Jquery) then i do ajax post using following code:
$.ajax({ type: "POST", url: "Page.aspx/MyMethod", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { // Do something interesting here. } });shailesh son...
Contributor
2273 Points
495 Posts
Re: Ajax Submit Issue
Jan 02, 2012 12:49 PM|LINK
Hi.
Take HTTPHandler, define your method in that as public and call it from Process_request method or put all your logic in process_request method instead of "MyMethod".
Call httphandler instead of "Page.aspx". it will work same. You need not to define it as static method in hadler.
Shailesh
If This post helps you to solve your problem please mark this as an answer.
SharePoint 2010:
http://weblogs.asp.net/shailesh/archive/2010/07/07/sharepoint-2010-introduction-to-client-object-model.aspx
bruce (sqlwo...
All-Star
37614 Points
5573 Posts
Re: Ajax Submit Issue
Jan 03, 2012 01:37 AM|LINK
page methods are an ajax callback. when you call a page method, the form data is not processed nor is the page life cycle run. it just a shortcut to build a web service.
also in your sample ajax call, no data is passed to the page method anyway.
JavedBoqo
Member
145 Points
144 Posts
Re: Ajax Submit Issue
Jan 03, 2012 05:28 AM|LINK
So basically what I have to do that all my server side code (in Page.aspx.cs) should be code in webservice which is very strange.
JavedBoqo
Member
145 Points
144 Posts
Re: Ajax Submit Issue
Jan 03, 2012 07:56 AM|LINK
hi
I have solved using following logic in my page_load event.Please inform me if this process has any drawback(s): I asume that when call from javascript then Request.HttpMethod will be "POST"
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString.ToString() != string.Empty) { if (Request.QueryString["action"] == constants.STATUS_OK) { lbl.Text = constants.STATUS_OK; } else { lbl.Text = constants.STATUS_ERROR; } } if(Request.HttpMethod.ToString().ToUpper()=="POST") { string redirectURL = "/forms/frmRegion.aspx?action="; redirectURL+=(RecordSave()==constants.STATUS_OK)?constants.STATUS_OK:constants.STATUS_ERROR; if (redirectURL.Contains(constants.STATUS_ERROR)) { lbl.Text = constants.ERROR; } else { Response.Redirect(redirectURL); } } }