Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

wwHoverPanel AJAX Control for ASP.NET posted


:P
On this page:

I've posted a first version of my wwHoverPanel control which provides some easy to use and high level remote call/AJAX functionality for ASP.NET Web applications. Since I originally posted a sample with my ScriptCallbacks samples some months ago there have been a lot of requests to post this control. I actually had posted it with several of my sessions given at various CodeCamps and user groups recently, but the control hadn't been quite finished and not documented. I spent a bit of time over the last week or so adding some functionality, adding documentation (which I needed to do anyway since this is part of our West Wind Web Store package) and creating some additional demos in preparation for my session at ASP.NET Connections.

 

This AJAX control is a control that provides a number of AJAX functionalities that I've been using in my own work into a single control that is easy to use. It's a fairly simple control that provides some core functionality and forgoes some of the fancy stuff that many other implementations are heading to (specifically ATLAS, Anthem and Ajax.NET all of which are heavily investing in AJAX driven 'stock' controls). I find that while these control driven architectures are fine they don't really address the business scenarios I work with – in those scenarios more core functionality that deals with passing application data back and forth and bringing down HTML snippets from the server are key.

 

Some of the concepts here aren't particularily new. Specifically the page callback functionality borrows heavily from Jason Diamond's MyAjax.Net/Anthem's original theme with some improvements from my end.

 

You can find the download, documentation and a link to the samples here:

http://www.west-wind.com/tools/wwHoverPanel/

 

The control is free comes with source code and the samples so you can check out in detail how it works, modify and tweak it. Note at the moment the code is for ASP.NET 2.0 only although the control itself includes only a few minor features that are 2.0 specific.

 

Here's what the control does:

 

  • HoverPanel Behavior
    You can drop this control onto a form and tell it to retrieve content from a URL and display it in a hover panel that pops up at the current mouse position of the page. The hover window pops ontop of the current content and retrieves its content asynchronously without reposting the entire page. Operation is by setting a base URL on the control, then calling a JavaScript generic function StartCallback() with the name of the control, the event object and an optional dynamic querystring on the appropriate even like a onmouseover. (
    example)

 

  • Page Method Callback
    In CallPageMethod mode the control allows you to callback onto the server and execute a method of the currently running ASP.NET page. Methods that are exposed to AJAX callbacks must have a [CallbackMethod] attribute. Server side methods can have normal .NET parameter and return value signatures with values marshaled two-way via JSON serialization. The JSON serializer works with most plain .NET objects including nested objects, nested arrays and collections as well as DataSet/DataTable/DataRow. The deserializer works with most simple objects including nested objects and nested arrays and IList implementing collections. The idea is that you can pass an object from the server to the client side, manipulate the object and pass it back. The control creates a client side wrapper object for the server methods, so you simply call the method with the same parameters that exists on the server, plus a Callback_Handler pointer to a function that handles the request. The function returns a single value that will be the result, or an exception object you can check for. Note that DataSet/Table/Row are not support for serialization back to the server! (examples:
    1 2 3)

 

  • Urlbased Callbacks
    You can also create a generic callback to another page in your Web application, retrieve the content and pass it back to a specified function. This is a very simple mechanism where you simply drop the control on the page add a client event handler that receives the result in the ClientEventHandler property and that method is called. (
    example)

 

Multiple Controls

You can drop multiple copies of the control on the page, so if you want multiple hover windows you'd assign one to each of these controls. The Urlbased Callbacks too map one callback to one handler.  Page level method callbacks only require one control on the page for all the methods that are published (you might need multiples if you have multiple simultaneous callbacks going).

 

Some other useful features

 

  • Set how to pass data back to the server (GET,POST,POSTNoViewState)
  • Set how the script code is embedded (WebResource,ExternalFile,EmbeddedInPage)
  • Automatically delay execution of the request (great for hoverpanels)
  • Automatic Callback detection (HoverControl.IsCallback)
  • Set Panel Opacity and Shadow

 

There's also some level of lower level control through Javascript code with a Context object for a particular control that maps most of the control properties, and low level methods like StartCallback and CallMethod that can be used directly from script to call back to the server.

Why this control?

You might ask, why this control? After all ATLAS is on its way and Anthem and Ajax.NET already live in this space. My biggest concern for ATLAS is that, well, it's not here yet and it looks actually quite a ways off yet. The last CTP was December and it completely broke the PDC functionality in almost all respects. So it's not something you can use today. I've really enjoyed Jason Diamonds MyAajax.NET/Anthem, but in recent months one it moved to SourceForge there have been so many break the build releases that I ended up not getting recent versions. There's a lot of feature creep from the original simple implementation which was nice and easy to integrate and work with. This may have changed now that it has actually gone V1.0. Ajax.NET is also another option and it's probably the most popular AJAX library out at the moment. I personally never got into this particular library because I felt it was more complex than it needed to be. In essence the theme between it and Anthem are similar although I feel that Anthem is the cleaner implementation. Personal choice and I'm sure others will disagree.

 

So this control fits somewhere on the lower end and doesn't go down the route of AJAX controls but rather focuses on getting content to your client application as easy as possible. The HoverPanel and Page Callback behaviors can be accomplished without writing any code other than the event handler. The Callback method that maps a client side class to the server published page methods is about as easy as it gets and was originally provided by Anthem.

 

I think the implementation of the callback interface is simpler than any of the other implementations, resulting in more efficient code especially for method callbacks.

 

One thing that Anthem was missing is two-way JSON support, which to me is important. I want to be able to pass an object to the client, modify it and send it back. For business scenarios this seems crucial and one of the most logical ways to do this. Now the JSON support in this control is spotty. Serialization is pretty good, but deserialization basically relies on Reflection and instantiation of objects on the server then populating public fields and properties with the values returned via JSON. For this to work with objects, the objects and all child objects must support parameterless constructors or arrays and collections. IOW, sending things up from the client might not work as smoothly.

 

Another feature is the ability to control how POST data is passed back to the server. In a lot of situations it makes good sense to send back the POST buffer from the client rather than passing an object back through a method call. Rather the control encodes all the form data and posts it back to the server. You can control if and how the data goes back with GET (no posting back), POST (posting full data including ViewState), POSTNoViewState modes to control the data. No ViewState can be handy if you have a lot of viewstate on the original page that loads. If you do post ViewState though ASP.NET will re-assign control value automatically so you can reference this.txtCompany.Text from within a callback. This will work for any control that has its state set entirely through POST data (like textboxes/checkboxes) but may not work for controls that rely on code to fill the data first like lists for example. In those cases you either need to make sure ViewState is enabled on these controls so the data gets restored through ViewState or you have to use an Explicit Request.Form["ListControl"] to retrieve the value. While this may seem hokey compared to passing values back via a method call, it's often much easier to write code on the server than trying to re-populate an object with the values from controls in Javascript code. I tend to rely on POST data extensively with the apps I've worked on.

 

So anyway, take a look, play around and let me know if you find a bug or think of some enhancements . Ok, I'm asking for trouble I'm sure…


The Voices of Reason


 

steve
February 08, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

Au contraire -- the older I get the less willing (lazy?) I am to spend my cycles clearing through the brush of new technologies being sorted out, industry hype, etc. Your site is a wonderful resource of knowledge and you are willing to share your pain of knocking your own head against some walls.

I wondered if the fact that you are not a Microsoft-is-always-right "type" is a reason you have not been invited to that conference again until now, and was glad to see that you got the call. People who have to work for a living need a fair view into what works and what doesn't.

I look forward to disecting your HoverPanel so I can learn about this type of AJAX implementation!

Carl Olson
February 08, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

Bella figura!

Fantastic! Thanks.

chris
February 08, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

Rick, you're my new favorite person!

Juma
February 09, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

Hi Rick,

The control works great except in a few scenarios.
* When we use the column to hover over as the last column in a grid the div tag goes beyond the screens visible area and if we move our mouse it goes away

* When we have a large grid. You hover over the first row it works fine. If we scroll the page down and hover over the last item you will not see the div (its actually there but is above your visible area) Again if we try to scroll back the div is gone.

One of my suggestions is that we should take into consideration the visible screen area and probably display the hover over div inside that. I will be working on that and will let you know if I fix it before you do. :-)

Thanks

Rick Strahl
February 09, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

Juma, there's actually a property - AdjustWindowPosition - that lets you to some degree control the placement.

The big problem is that there's no reliable way to exactly figure out the visible area of the page that I could manage. AdjustWindowPostion works as long as the document size itself is larger than than the area you're trying to load the window over (ie. a big column on the left for example).

Take a look at the ItemList here:
http://www.west-wind.com/wwStore/itemlist.aspx

If you resize the window so the bottom of the list is cut off or close to the bottom you'll see the window move up.

I have code like this:

var Top = 0;
if (document.body.scrollTop)
Top = document.body.scrollTop;
Top = Top + Context.LastMouseTop + 3;

Panel.style.top = Top.toString() + 'px';
Panel.style.left = (Context.LastMouseLeft + 2).toString() + 'px';
Panel.style.display = '';

if (Context.AdjustWindowPosition && document.body)
{
if (document.body.clientHeight < Top + Panel.clientHeight )
Panel.style.top = (document.body.clientHeight - Panel.clientHeight - 10 + document.body.scrollTop).toString() + 'px';
}

that deals with this. If anybody has a better idea of figuring out the active window area <g>...

Mike McDonald
February 09, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

I'm using the following script, which helped with an issue I had with misplaced divs. This is not the actual code I'm using - it has been tweaked slightly to somewhat match your code..

var mainHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) { mainHeight = window.innerHeight; }
else if( document.documentElement && document.documentElement.clientHeight ) { mainHeight = document.documentElement.clientHeight; }
else if( document.body && document.body.clientHeight ) { mainHeight = document.body.clientHeight; }

Panel.style.top = (Context.LastMouseTop + document.body.scrollTop + 2).toString() + 'px';
Panel.style.left = (Context.LastMouseLeft + 2).toString() + 'px';
Panel.style.display = '';

if (document.body)
{ if ( mainHeight < Panel.clientHeight )
{ Panel.style.top = document.body.scrollTop; }
else { if ( document.body.clientHeight < Context.LastMouseTop + Panel.clientHeight )
{ Panel.style.top = document.body.clientHeight - Panel.clientHeight - 10 + document.body.scrollTop; }
}
}

- Mike McDonald
Software Design of Kentucky

Rick Strahl
February 17, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

Hi Mike,

Thanks for the code. Yes that works well actually, i've integrated that into the code and it seems to work well in all the places I use the control.

slolife
February 23, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

The download link appears to still point to the original 1.0 zip file. Is there a new location?

Rick Strahl
February 23, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

I pulled the update as there was a problem with it. I'll put it back up in a few minutes.

Rick Strahl's WebLog
February 23, 2006

# A few updates to the wwHoverPanel Control

I've updated the wwHoverPanel control with a couple of fixes, one of which was a pretty major issue dealing with the control living in a container...

Russ
July 17, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

This control is fantastic. I was able to implement it in minutes!

Are there any plans to have AdjustWindowPosition handle horizontal permission? I am using your control in a calendar. Events on Friday or Saturday are far to the right, which makes the hoverpanel run off the screen to the right.

Thanks!

Russ
July 17, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

Forgive my previous typo ... I meant "horizontal position".

3051S压力变送器
August 06, 2006

# re: wwHoverPanel AJAX Control for ASP.NET posted

Thanks for the code. Yes that works well actually, i've integrated that into the code and it seems to work well in all the places I use the control.

Web Forms
October 17, 2006

# ASP.NET Forums - Postback probem


Client Side Web Development
November 09, 2006

# ASP.NET Forums - PopOver window



November 16, 2006

# 面向.NET开发人员的Ajax 技术平台策略 - ccBoy&#39;s (小气的神) BLOG


千里之外
March 25, 2007

# 千里之外 - 博客.CN[blogger.cn/blog/中国/china]


ASP.NET Forums
May 21, 2007

# PopOver window - ASP.NET Forums



May 21, 2007

# 面向.NET开发人员的Ajax 技术平台策略(转) 原作者:小气的神 - 回头再说 坚强2002的博客 - 博客园



July 05, 2007

# ajax总体概述 - wsky - 博客园


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024