Solved

calling controller using JQuery ajax calls

Posted on 2011-03-21
3
579 Views
Last Modified: 2012-05-11
Hi...i have a user control contains  3 textboxes and a button
 added to a aspx page .  When clicked it should make a ajax call to controller and pass data of textboxes and it should return a message....how can i do this
0
Comment
Question by:praveen7k
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
chuckalicious earned 500 total points
ID: 35189658
A little bit tricky to comment without seeing an example page, or example content. I'm not familiar with aspx, but assuming you wanted to pass the values back using POST, you could do something like the following:

Textboxes are in format <input type="text" name="field1" value="" /> etc

Basically what I'm doing here is binding a click event to the element of a given ID, in this case your button. I am then setting 3 variables, each with the value of the relative text box (not you may want to correctly escape these depending on content) and then I am performing a jQuery POST to a given URL and passing it 3 value pairs, in the format of <value name>:<value>

There are other things you can do to check that the AJAX query returned a success or error, so I suggest you look at the documentation which is very helpful http://api.jquery.com/jQuery.post/



$(function() {
$("<id of button element>").click(function(){
    //in here you need to build a list of the answers, for example
    var  val1=$("input[name='field1']").val();
    var  val2=$("input[name='field2']").val();
    var  val3=$("input[name='field3']").val();

   //now do a post using jQuery AJAX
	$.post("url of your receiving page", {entered_text1 : val1, entered_text2 : val2, entered_text3 : val3}, function(data){
		if (data.length>0){
			//do something
		} 
	}); 
})
})

Open in new window

0
 

Author Comment

by:praveen7k
ID: 35223654
This was helpful for textboxes.....
In my rek there is third part uploadify control ..so here usercan upload 1o files max..so when i click button it should make a ajax call to controller it should post all these attachments to the controller ...is there any way to do this.....
0
 
LVL 4

Expert Comment

by:chuckalicious
ID: 35230392
I don't think there's an easy way to do Ajax file uploads. I've looked at this for PHP using POST. I would Google AJAX file uploads and see what you get.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question