|
|
|
|
|
Home
»
AJAX
»
Simple Server Callbacks using JQuery in ASP.Net page
|
|
|
|
Author Rank :
|
|
|
Page Views :
|
7808
|
|
Downloads :
|
235
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
|
|
|
Download
Files:
|
|
|
|
|
|
|
|
|
|
|
|
Using server side Ajax in asp.net is not much faster as Jquery ajax calls. Here I'm showing you how to prepare ajax calls using jquery and showing the data coming from server side to html page without any postback.
First you need to download the latest Jquery file from here. Add the script tag in the head of the page.
<script type="text/javascript" src="Scripts/jquery.min.js"> </script>
or you can use following script tag to use it from google code if you are connecting to internet.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"> </script>
Now your page is ready to use the JQuery function in your page. Next you have to do is to write the following script inside you head tag.
<script type="text/javascript"> function showDetails(){ $("#divResult").load("InfoDisplay.aspx", { action: $("#TextBox1" ).val() }); } </script>
What this function is doing is, $("#divResult") is identifying the div tag in which the information that will come from callback will be displayed. The next is $("#divResult").load(), this function takes three arguments
-
Page to display
-
Optional parameters to send with the page request
-
Action after result of the callback
Now here we have used only first two options.
load("InfoDisplay.aspx", this is the URL of requested page.
{ action: $("#TextBox1" ).val() }); This is the Parameter named "action" and value is Text of a TextBox1 control.
Now the coding of the rest aspx page will be like this:
<body> <form id="form1" runat="server"> <div> Enter word to get Details: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <input type="button" id="btnGetDetail" value="Click me" onclick="showDetails();" /> <div id="divResult" style="width:420px"></div> </div> </form> </body>
Now you have to create page InfoDisplay.aspx like below
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <fieldset> <legend>This is loaded from infoDisplay.aspx page using Jquery Ajax callback</legend> <hr /> <b> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></b> <hr /> hello <br /> #######################?? <br /> #################################################<br /> #####################. <asp:Image ID="Image1" runat="server" ImageUrl="~/image/asd.jpg" Height="130px" Width="120px" /> </fieldset> </div> </form> </body> </html>
And it's code behing page_load will be like this:
protected void Page_Load(object sender, EventArgs e) { string symbol = Request.Params["action"] ?? ""; Label1.Text = symbol; }
And now run the project and see how fast it is using Jquery callbacks.
Download the attached project for sample. Aspx files are inside SimpleLoad folder.
Happy Coding...
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
Amit Choudhary
Amit is a software developer by profession and blogger by choice. He's Practicing in C#, .Net
framework, ASP.NET, Silverlight, Windows Phone, ADO.NET, Linq, Xml, Web Services, JQuery, and Sql server. Amit is MindCracker MVP. Visit Amit's blog - www.cshandler.com
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|