Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 19th, 2009, 10:01 PM
jminatel's Avatar
Wrox Staff
Points: 17,437, Level: 57
Points: 17,437, Level: 57 Points: 17,437, Level: 57 Points: 17,437, Level: 57
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Location: Indianapolis, IN, USA.
Posts: 1,933
Thanks: 57
Thanked 128 Times in 97 Posts
Default Article: jQuery with ASP.NET 3.5 SP1

This article is excerpted from the Wrox Blox PDF Download "New Features in ASP.NET 3.5 Service Pack 1" by Wally B. McClure and is reused by permission of the publisher. This may not be reused without publisher permission



jQuery

While technically not a feature of .NET 3.5 Service Pack 1, Microsoft announced shortly after the release of Service Pack 1 that the open source jQuery JavaScript library would be included in future versions of Visual Studio. In the meantime, they have released an IntelliSense-encoded version of jQuery, and it has been donated to the jQuery organization. This IntelliSense-encoded file can be used to get full IntelliSense support for jQuery within Visual Studio 2008.
It is impossible to do a complete overview of jQuery in the matter of three to five pages. One of the cool features it provides is the ability to directly call a Web Service without need for the ASP.NET ScriptManager. With jQuery, it handles communication with the Web Service as well as getting the data back and interacting with the result without using the ASP.NET AJAX Script Manager.
Before you delve into the following code example, where the code calls out to the ReturnData method in the GetData.asmx Web Service, let’s look at the parameters that are passed in:
  • When the document.ready event occurs in jQuery, the code within the defined function is called.
  • A call is made to a Web Service in AJAX. The call to $.ajax() initiates this.
  • The type: value is used to set the type to call. In this example, the value is set to POST. As a result, the Web Service is called with a post.
  • The contentType: value sets the type of data that is being sent between the client and server.
  • The data: value contains the values that are being passed to the Web Service.
  • The dataType: value sets the type of data format that is supposed to come back from the server.
  • On a successful result, the method specified within the success: value is called.
  • If an error occurs, the method specified by the error: parameter is called.
javascript Code:
<label for="lblOutput">
    Text Out:
</label>
<div id="lblOutput" />
<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "GetData.asmx/ReturnData",
            data: "{i: 47}",
            dataType: "json",
            success: function(msg) {
                var newline = "<br />";
                $('#lblOutput').html("Name: " + msg.d.Name + newline +
                "Notes: " + msg.d.Notes + newline +
                "Passed Value: " + msg.d.PassedValue);
            }
            error: function() {
                alert("An error occurred on the server.");
            }
        });
    });
</script>
</div>
<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "GetData.asmx/ReturnData",
            data: "{i: 47}",
            dataType: "json",
            success: function(msg) { onSuccess(msg); },
            error: function() {
                alert("An error occurred on the server.");
            }
        });
    });
    function onSuccess(msg) {
        var newline = "<br />";
        $('#lblOutput').html("Name: " + msg.d.Name + newline +
                "Notes: " + msg.d.Notes + newline +
                "Passed Value: " + msg.d.PassedValue);
    }
</script>

What makes the jQuery library so advantageous is that it integrates with existing ASP.NET AJAX Web Services, and it does not require any of the overhead of the ASP.NET AJAX ScriptManager. While this does not sound like much, every byte of data that does not need to be downloaded helps performance.
Figure 5 shows the output of the sample code.
The question that I am sure that developers are asking is, “Why would I use jQuery instead of calling through ASP.NET AJAX?” ASP.NET AJAX provides simple and easy support for calling Web Services. That support comes at a price of more information being downloaded from the service to the client browser. jQuery provides support for calling Web Services. However, the development experience is not quite as good. However, the result is a slight improvement in performance in general. This comes about because less material is downloaded to the client browser from the server.
Attached Images
File Type: png 457344 McClure Fig05.png (63.2 KB, 59 views)
__________________
Jim Minatel
Associate Publisher, WROX - A Wiley Brand
Blog: http://p2p.wrox.com/content/blogs/jminatel
Wrox on Twitter: http://twitter.com/wrox
Did someone here help you? Click on their post!

Last edited by jminatel; February 20th, 2009 at 01:12 AM.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ask a article about ASP.NET 2.0 stonefang Classic ASP Professional 0 May 18th, 2007 01:20 AM
article posted: ASP.NET 2.0 security jminatel ASP.NET 2.0 Professional 0 May 11th, 2006 03:45 PM
Article posted: Using SOAP Headers with ASP.NET jminatel XML 0 May 5th, 2006 05:30 PM
New article posted:Using SOAP Headers with ASP.NET jminatel ASP.NET 2.0 Professional 0 May 5th, 2006 05:28 PM



All times are GMT -4. The time now is 08:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.