Work smarter: MS AJAX’s JavaScript type extensions

AJAX, ASP.NET, JavaScript By . Updated September 28, 2008

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 read the rest of this post »

Using pageLoad in both Master and Content pages

AJAX, ASP.NET, JavaScript By . Updated October 10, 2008

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 . Posted November 15, 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 read the rest of this post »

Inline Edit Box .NET (v0.7)

AJAX, ASP.NET, JavaScript, UI By . Updated October 10, 2008

Mike’s been extremely busy this month, but found time to update Inline Edit Box .NET for us. Changes since version 0.5 include:

  • Added option for single click or double click (new Public Property called ClickMode: enum [SingleClick|DoubleClick])
  • Added ClientIDSuffix property to allow for repeater/web control objects.
  • Added Mode property. Allows to specify Admin or Display modes.
  • Fixed PostBack issues with regards to control properties.

Head over to the Inline Edit Box .NET page for the download link and more information.

Are you making these 3 common ASP.NET AJAX mistakes?

AJAX, ASP.NET By . Updated April 21, 2008

It’s important to remember that a partial postback is just that: A postback.

The UpdatePanel’s way of abstracting AJAX functionality behind standard WebForm methodology provides us with flexibility and familiarity. However, this also means that using an UpdatePanel requires careful attention to the ASP.NET Page Life Cycle.

In this post, I’d like to point out a few of the problems I’ve seen developers running into and what you can keep in mind to avoid them:

  • Page events still fire during partial postbacks.
  • UpdatePanel events fire, even when not updating.
  • Control event handlers fire after Load events.

Click here to read the rest of this post »

Easy incremental status updates for long requests

AJAX, ASP.NET, JavaScript, UI By . Updated October 15, 2008

Animation of the multi state progressA problem that has always plagued web developers has been providing detailed progress indication for server-side tasks. The stateless nature of the HTTP protocol makes implementing a mechanism for constant, stateful progress information cumbersome. The main problem is that a given group of server side tasks will generally only result in one, aggregate response from the server.

In the ASP.NET community, several solutions have been offered. Some even provide an entire framework for monitoring the status of tasks in progress. However, they are convoluted and depend on constant server polling. I find polling for progress indication to be an inefficient approximation, when exact data is readily available.

With that in mind, I’d like to share an alternate method that I’ve used in the past with great success.

Click here to read the rest of this post »

ASP.NET AJAX Timer Trouble? Location is key.

AJAX, ASP.NET, JavaScript, Performance By . Updated October 10, 2008

If you’ve made much use of the ASP.NET AJAX Timer control, you may have noticed that it can behave somewhat unexpectedly. In this post, I’m going to take a closer look at how the Timer works and the most significant factor that influences it: Location.

Where the timer is placed on the page actually varies how it operates. As a Timer’s delay interval approaches the processing time of its resulting PostBack, the difference that the Timer’s location makes becomes very significant.

Click here to read the rest of this post »

Seamless inline text editing: The Control!

AJAX, ASP.NET, UI By . Updated October 10, 2008

In my recent post, Seamless inline text editing with ASP.NET AJAX, I thought I had outlined the simplest possible way to implement the technique, but I was wrong. One of my readers, Mike Davis, took what I began and built it into the beginnings of a great ASP.NET server control.

The initial release is available here: Inline Edit Box .NET

With it, you can transparently implement the inline editable label functionality with only one line of code. He’s not finished refining it and adding new features yet, so he would like your input on where to go from here.

Download it, give it a try, and leave Mike some feedback in the comments on the download page today!

Seamless inline text editing with ASP.NET AJAX

AJAX, ASP.NET, JavaScript, Performance, UI By . Updated October 15, 2008

Inline text editing animationThis is a technique that I really like. It’s excellently suited to intranet sites and administrative interfaces, where your users are typically familiar enough with the application to know which text they can click to edit. It’s actually very easy to implement, with a small amount of JavaScript.

Click here to read the rest of this post »

Updated your web.config, but Sys is still undefined?

AJAX, ASP.NET, JavaScript By . Updated January 16, 2012

Sys is not defined error message

If you Google the error you’ll find a lot of results about updating your web.config to enable ASP.NET AJAX (which is a necessary step), but what if you’ve already done that? Not only will your search be an exercise in frustration, but it will lead you down the wrong path completely. Maybe I can help.

Click here to read the rest of this post »