1

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.

4 Answers 4

1

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/

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your info.I need to pass values from a lot of textbox.So here you are passing only one textbox value.So how can i pass values from a group of textbox
is it a known number of textboxes? if so, you could add that number of parameters to the web method, and pass each textbox's value into its own parameter...
1

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

1 Comment

I know that I can do implement ajax using $ajax.But I done by sending values through parameter with the url.But Now I need to get all the values in the textboxes of 'a.aspx',in the function defined in the 'a.aspx.cs' page.Can I able to do this?
0

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

1 Comment

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.