kbvishnu
kbvishnu

Reputation: 15630

Jquery ajax in ASP.Net Form

I am having a aspx page and it contains aspx controls.Is there any way to use jquery ajax function to save some data.I need to get the values of the textbox.I am not prefering to pass all the values through querystring. Can u pls specify a method to implement here.Thnaks in advance.

Upvotes: 1

Views: 390

Answers (4)

kbvishnu
kbvishnu

Reputation: 15630

I got the solution . Please visit this article in code project.

http://www.codeproject.com/Articles/105210/Easy-Way-to-Implement-Ajax-using-Jquery-in-ASP-NET.

Upvotes: 0

Brandon Montgomery
Brandon Montgomery

Reputation: 6986

You'll need a couple of things. First, you'll need a web service in your ASP.NET application to "catch" your AJAX post. You can put this service method in your page, or you can make a new web service. If the service method will live in your page, it will look something like this:

<WebMethod()> _
<ServiceMethod(ResponseFormat:=[I forget the namespace].Json)> _
Public Shared Function MyServiceMethod(ByVal property As String) As String
  'Do something
  'return something
  Return 1
End Function

Next, you'll need to use jQuery to make an AJAX post to that web service method. Make sure you use the ClientID of the textbox from which you are grabbing the data you need to send. Also make sure you specify 'POST' as the method, and not 'GET' (which is the default). Something like this:

$.ajax({
  url: 'MyPage.aspx/MyServiceMethod',
  type: 'POST',
  contentType: 'application/json',
  data: '{ property : $("#<%=txtMyTextBox.ClientID %>").val() }',
  dataType: 'json'
});

Here is the full jQuery AJAX documentation: http://api.jquery.com/jQuery.ajax/

Upvotes: 1

Jaime
Jaime

Reputation: 6814

Yes you can do it. Just get the values from the text boxes and use $.ajax to post the data to the server.

Upvotes: 0

Pranay Rana
Pranay Rana

Reputation: 176916

jQuery.ajax( settings ) : Perform an asynchronous HTTP (Ajax) request.

Upvotes: 1

Related Questions