Solved

calling controller using JQuery ajax calls

Posted on 2011-03-21
3
588 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

830 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