Using jQuery to Consume ASP.NET JSON Web Services

AJAX, ASP.NET, JavaScript, Performance, UI By Dave Ward on March 27th, 2008

In response to many of the articles here, I receive feedback asking how to achieve the same results without using ASP.NET AJAX. As much as I’m a fan of ASP.NET AJAX, I must agree that its JavaScript payload can certainly be a drawback in some situations.

My recent deferred content loading post is an excellent example of that. I was using jQuery for presentational effects, and using a ScriptManager to call a web service. Loading the JavaScript for both frameworks was a bit counterproductive, since the whole point was to improve initial load time.

In this post, I intend to correct that.

First, I’ll cover the two requirements necessary when calling an ASMX web service that’s being JSON serialized by the ASP.NET AJAX extensions. Then, I’ll show you how to do this with jQuery. Finally, I’ll update the deferred content loading example accordingly.

Click here to continue reading this entry »

Why my ASP.NET AJAX forms are never submitted twice

AJAX, ASP.NET, JavaScript, UI By Dave Ward on March 4th, 2008

The overzealous double-clickers amongst our users often make it desirable to temporarily disable the controls that trigger server side processing. Previously, I’ve shown you how to disable a button during a postback, how to disable a button during a partial postback, and even written a server control to automate the latter.

However, what if you wanted to be more thorough and disable all of the buttons on a page?

In this post, I’m going to show you how to do just that. I’ll also show you how to disable only the buttons in the UpdatePanel raising the event. Finally, for the jQuery users out there, I’ll show you how to simplify the process down to one line of code.

Click here to continue reading this entry »

Boost ASP.NET performance with deferred content loading

AJAX, ASP.NET, JavaScript, Performance, UI By Dave Ward on February 5th, 2008

FireBug graph of net requests
When rolled into the page life cycle of an ASP.NET WebForm, that red bar is one of your application’s greatest enemies. No matter how well you optimize the rest of the page, even one slow task can become the sole factor determining a user’s perception of the entire page’s performance.

In this post, I’m going to show you one way to circumvent that problem. By placing ancillary content in user controls and delaying their load until the core page content has been displayed, you can drastically improve perceived performance.

When broken down into digestible chunks, the technique is easy to implement and lends your application a level of polish that your users are sure to appreciate. The four steps required to accomplish this will be: building the user control, statelessly rendering the control as HTML, providing progress indication, and using ASP.NET AJAX to request and inject that HTML.

Click here to continue reading this entry »

4 ASP.NET AJAX JavaScript UI methods you should learn

AJAX, ASP.NET, CSS, JavaScript, UI By Dave Ward on January 9th, 2008

Wrapping up my series on some of ASP.NET AJAX’s less utilized client side functionality, this post will take a closer look at some of ASP.NET AJAX’s JavaScript UI helper functions. These methods are great because they abstract away most of the tedious work that comes with supporting cross browser compatibility, leaving us with a nice, consistent API.

Specifically, I’m going to show you examples of using addCssClass, getBounds, getLocation, and setLocation to accomplish a few client side UI tasks.

Click here to continue reading this entry »

Best of 2007: 5 most popular posts (and contest winners)

AJAX, ASP.NET, JavaScript By Dave Ward on December 21st, 2007

As of today, the site is exactly one year old. What a year it has been!

I would like to sincerely thank every one of you for making this past year such a blast. Without all of your great comments, emails, links, and kicks, I doubt that I would have been motivated enough to keep putting in all the work that it takes to run this site.

I would also like to especially thank Joe Stagner, Scott Guthrie, and the DotNetKicks community for their considerable support this year.

Click here to continue reading this entry »

Three copies of ASP.NET AJAX in Action still available

AJAX, ASP.NET, JavaScript By Dave Ward on December 20th, 2007

If you haven’t seen the original post with details on the contest, read that first.

If you have, then you know that we’re down to the last day of the contest. So, make sure that you’ve maximized your chances of winning by commenting on the original post and subscribing to my email list.

As promised, if you’re viewing this post in an RSS reader, it will contain instructions on the third way to win your own copy of ASP.NET AJAX in Action. If you haven’t subscribed to the Encosia RSS feed yet, it’s not too late. Even if you subscribe now, you’ll still see the instructions in the footer of this post’s feed entry.

Best of luck to everyone!

Three copies of ASP.NET AJAX in Action up for grabs

AJAX, ASP.NET, JavaScript By Dave Ward on December 17th, 2007

Thanks to Alessandro Gallo and Manning Publications, I am happy to announce that I’m going to be giving away three copies of ASP.NET AJAX in Action this week in celebration of my blog’s one year anniversary.

If you haven’t read ASP.NET AJAX in Action, you really owe it to yourself to check it out. The book does a great job of helping you understand what’s actually going on under the hood, not just the syntax of the controls. That sort of intimate understanding of the fundamentals is crucial when creating real-world AJAX solutions.

The book goes on to explain all of the ASP.NET AJAX server controls and show full examples of their use, while continuing to keep you aware of any consequences that a particular strategy might have. It also delves into more advanced topics a bit, like building AJAX enabled controls, the ASP.NET AJAX futures, and how to maintain unique URLs for intermediate points in your AJAX application’s workflow.

I don’t generally read technical books about practical application, but I couldn’t put this one down. If you’re reading my site, there’s an awfully good chance that you’d enjoy this book.

Now, on to the fun stuff. I’m going to select winners for the books in three different ways:

Click here to continue reading this entry »

Work smarter: MS AJAX’s JavaScript type extensions

AJAX, ASP.NET, JavaScript By Dave Ward on December 4th, 2007

In my last post, I began a series exploring ASP.NET AJAX’s client side functionality. If you missed it, you can catch up by reading that post about the various uses of $addHandler.

In this post, I want to take a look at a few more under-appreciated tools that we’re provided with as a part of the framework: Base type extension methods.

Specifically, I’m going to provide some examples of using Array.contains, Date.format, and String.format.

Click here to continue reading this entry »

Using pageLoad in both Master and Content pages

AJAX, ASP.NET, JavaScript By Dave Ward on November 20th, 2007

Reader Kevin posed a good question in response to my last post, the answer to which is useful enough to warrant a separate post:

I have a situation where I call a page load handler from a script associated with a master page, then on a specific page based on that master page I need to call a second page load handler. I use the pageLoad() shortcut notation in the master page script. I can’t get either pageLoad() (expected since the composite page would have two pageLoad’s) or $addHandler(document, “load”, mySpecificPageLoad()) to work. I had to resort to my old “addLoadListener” function to add the second page load event handler. Is this as expected?

As he mentions, there’s only room in the page’s DOM for one pageLoad shortcut function, preventing both a master and content page from utilizing the shortcut simultaneously.

To work around this limitation, simply add this to your master’s pageLoad:

<script type="text/javascript">
  function pageLoad() {
    // Master pageLoad() code.
 
    // If function contentPageLoad exists, execute it.
    if(typeof contentPageLoad == 'function')
      contentPageLoad();
}

Now, contentPageLoad is executed on any content page you wish to include it on, just as if it were pageLoad. If you don’t include it on a particular content page, the conditional will prevent its execution (and subsequent JavaScript error).

You could use Sys.Application.add_Load to wire up a custom pageLoad on every single content page, but I think the DRY-ness of this approach is preferable. The above method also allows you to retain control of the order of execution, through the placement of the contentPageLoad call in pageLoad.

Exploring one of MS AJAX’s often overlooked features.

AJAX, ASP.NET, JavaScript By Dave Ward on November 15th, 2007

It’s easy to think of the ASP.NET AJAX framework primarily in terms of the server controls it provides. However, make sure that you don’t overlook the client script helper classes at your disposal. Many of them are very useful and surprisingly powerful.

In the next several posts, I’ll be examining these client side helper classes and hopefully giving you some ideas for more effectively using them.

In this first post, I’m going to take a closer look at $addHandler.

Click here to continue reading this entry »