Blog - Microsoft .NET, ASP.NET, AJAX and more

ASP.NET 4.0 AJAX Issues

by Damien White 8/27/2009 8:14:58 PM

PuzzledMan I’ve been using ASP.NET AJAX 4.0 quite a bit lately in ASP.NET 3.5 applications.  I encountered two issues tonight, and I hope this post saves someone some grief.

The first problem has to do with referencing the ASP.NET AJAX 4.0 library within an ASP.NET 3.5 application, and the second was a surprising data binding issue using the DataView

If you are looking for more information on ASP.NET AJAX 4.0, be sure check out my other articles on the site.

Issue 1 – The ScriptManagerProxy and CompositeScripts

The first issue I encountered was a client side error when using the DataView on a content page in my ASP.NET 3.5 SP1 application.  This site utilizes master pages, so I’m using a WebForm, otherwise I probably would have just gone with a plain old HTML page.  Regardless, since this is an ASP.NET application and the ScriptManager is declared in the Master page, I added the ASP.NET 4.0 AJAX scripts to a ScriptManagerProxy (instead of the ScriptManager itself). The code for the ScriptManagerProxy looks very similar to that for the ScriptManger.

More...

Shout it kick it on DotNetKicks.com Bookmark and Share
Tags:
Categories: AJAX | ASP.NET
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

ASP.NET AJAX 4.0 and the ScriptManager Control

by Damien White 6/1/2009 7:15:48 PM

Puzzle Pieces I have been using ASP.NET AJAX 4.0 quite a bit lately, as I’m sure most of you are aware from my recent posts.  In those posts, I used standard HTML script references to show that ASP.NET AJAX is not reliant upon ASP.NET.  I realize that many of you are in fact using ASP.NET, and today we will take a look at using the ScriptManager. 

First we’ll look at using the Preview 4 scripts within an ASP.NET 3.5 application (with the ScriptManager of course) as well as using client templates and ADO.NET Data Services with the ScriptManager in ASP.NET 4.0 (Beta 1).  After that, we’ll take a closer look at some of the new features of the ScriptManager in ASP.NET 4.0. 

Preview 4 and the ASP.NET 3.5 ScriptManager

In my posts on ASP.NET AJAX 4.0 so far, I used standard HTML script references (as stated earlier).  However, what if you wanted to incorporate the new ASP.NET AJAX 4.0 scripts with a ScriptManager.  I tried this in a recent ASP.NET 3.5 SP1 project, and ran into some issues getting it all to work out.  Thanks to this blog (and Bertrand LeRoy), I found the solution.

<asp:scriptmanager id="sm" runat="server">
<scripts>
<asp:scriptreference scriptmode="Inherit" name="MicrosoftAjax.js" path="~/scripts/MicrosoftAjax.js" />
<asp:scriptreference scriptmode="Inherit" path="~/scripts/MicrosoftAjaxAdoNet.js" />
<asp:scriptreference scriptmode="Inherit" path="~/scripts/MicrosoftAjaxTemplates.js" />
</scripts>
</asp:scriptmanager>

More...

Shout it kick it on DotNetKicks.com Bookmark and Share

ASP.NET 4.0 AJAX – Preview 4 – Data Binding

by Damien White 5/27/2009 10:48:29 AM

LaptopThroughout the course of my introductory posts on ASP.NET AJAX 4.0, we looked at the new DataView control as well as the Sys.Observer class, which brings the Observer pattern to plain JavaScript objects.  The new ASP.NET AJAX release is very exciting offering powerful new features to take AJAX enabled applications to a new level.  In this post, we’ll look at another exciting feature of ASP.NET AJAX 4.0 known as “live bindings.” 

You may remember that we looked briefly at live bindings in the client templates post, but for those examples I used one-way / one-time bindings.  Today, we’ll take a closer look at live bindings and see how two-way live bindings removes the one-way / one-time binding restriction allowing us to update bound elements on our page automatically when the underlying data changes. 

Again, in this post, I’ll be using Preview 4 of the ASP.NET AJAX Library, which can be downloaded from CodePlex.  The Preview 4 version can be used in your applications today (e.g. ASP 3.5, HTML).  Keep in mind that these components are still in "preview" mode (meaning no Microsoft support), though they are usable at your own risk.  For more information, you can check out the license on CodePlex. More...

Shout it kick it on DotNetKicks.com Bookmark and Share

Wrox Blox - ASP.NET AJAX Control Development with Visual Studio 2008 and .NET 3.5 Framework

by Damien White 4/28/2008 11:28:17 PM
Technorati Tags: ,,

ASP.NET AJAX Control Development with Visual Studio 2008 and .NET 3.5 Framework Wrox BloxI'm happy to announce that my second Wrox Blox is done and available for purchase as of today!  As you may remember, back in January, my first Wrox Blox on the ASP.NET AJAX Control Toolkit was released.  Now, continuing with the ASP.NET AJAX theme, the new Wrox Blox deals with creating your own ASP.NET AJAX controls, from scratch.  As you may or may not know, control development is one of my favorite topics.  There are always times when you create something that you and others will useful in multiple applications, and these cases usually are good candidates for a server control.  This book takes the "Server Control" to the next level by enabling a rich client interface with ASP.NET AJAX.  If you are still working in VS 2005, don't let the title scare you away.  Even though the book focuses on VS 2008 and .NET 3.5, you'll still find the code and concepts apply within VS 2005 with .NET 2.0 and ASP.NET AJAX Extensions 1.0.  More...

Shout it kick it on DotNetKicks.com Bookmark and Share

ASP.NET AJAX Control Development and the Chatty onMouseOut Event

by Damien White 3/24/2008 8:40:00 AM
Technorati Tags: ,,,

If you have been working on developing ASP.NET AJAX web controls, there is a good chance that you may have encountered some issues with the onMouseOut event.  The issue comes about when you are developing a container-type control (e.g. a Panel or DIV) and you wish to capture the mouse out event on the parent container.  A container control contains children, and what ends up happening is when you move your mouse around the control, you'll find that onMouseOut fires for the parent even though the mouse hasn't left the container.  The problem is due to event bubbling.  This probably isn't anything too new for you if you have done a lot of JavaScript and there are solutions on the Internet that discuss this issue.  However, in an ASP.NET AJAX Control, the process is similar to the straight JavaScript equivalent, but there are some changes to be aware of.

The solution involves performing a test on the element that the mouse is now on.  The element can be retrieved using the relatedTarget in FireFox or toElement in Internet Explorer.  Once we have the element, we will make sure that it isn't the element itself or a child of the element.  Remember, we only want to fire the onMouseOut event when the mouse has fully left the parent.  The setup here is that you have an ASP.NET AJAX Control that has a method named _onMouseOut where you have already created the handler and such for it.  If you aren't familiar with this, I would recommend checking out the ASP.NET AJAX Documentation under the ASP.NET AJAX Extensibility section, specifically, a good example is this one, which illustrates using the IScriptControl.

The Solution

_onMouseOut : function(e) {
    /// <summary>
    /// Handler for the Control's mouseout event
    /// </summary>
    /// <param name="e" type="Sys.UI.DomEvent">
    /// Event info
    /// </param>    
    
    // Access the raw event since we need the relatedTarget/toElement
    var ev = e.rawEvent;    
    
    // Access the DomElement; this is the parent we will be testing
    var parent = this.get_element();
    
    // Access the element the mouse is now over
    // relatedTarget = FireFox; toElement = IE
    var rel = (ev.relatedTarget) ? ev.relatedTarget : ev.toElement;
    
    // Ensure the mouse isn't still over the control
    // And make sure the mouse isn't over a child of the control
    if (parent != rel && !this._isChild(parent, rel)) {
        // TODO: Handle OnMouseOut        
    }
},
// Helper Methods 
_isChild : function(parent, child) {
    /// <summary>
    /// Helper method to determine if an element is a child of a parent DomElement
    /// </summary>
    /// <param name="parent" type="Sys.UI.DomElement">
    /// The parent element
    /// </param>          
    /// <param name="child" type="Sys.UI.DomElement">
    /// The element to check if it is a child of the parent
    /// </param>  
    
    // Make sure that the child node isn't null
    if (child != null) {
        
        // While the child still has a parent node
        while(child.parentNode) {
            // Move up the chain of parents
            child = child.parentNode;
            
            // Test if the test parent element is in the chain
            if(child == parent)
                return true;
        }
    }
    // Element isn't a child of the parent
    return false;
} 

I have added inline comments to make the code self-explanatory, I feel it is pretty straightforward to understand.  In addition to the _onMouseOut method, you can see I also added a helper method to test if an element is a child of a parent element.  You can trim these down into a single function if you'd like.  The one thing that you may find confusing is accessing the rawEvent.  Note that the event argument passed in an ASP.NET AJAX Control is of the type  Sys.UI.DomEvent, not the native DOM event, so hence the rawEvent property, which exposes this.  The DomEvent contains this property even though it isn't listed in the ASP.NET AJAX Documentation as of this writing.

I came up with this technique after doing some research on the Internet and came across this post on the CodeHead forums as well as this one on QuirksMode.org.  Using these ideas, I tweaked them to get them to work within the context of an ASP.NET AJAX Control.  

Shout it kick it on DotNetKicks.com Bookmark and Share