Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

calling controller using JQuery ajax calls

Posted on 2011-03-21
3
Medium Priority
?
603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
chuckalicious earned 2000 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

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

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…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

670 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