Solved

calling controller using JQuery ajax calls

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
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…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now