Aspects to modify behavior of controls

Modified: 2008/09/04 22:48 by RugWarrior - Uncategorized
Edit

Background

Aspects are a really cool feature in Gaia which unfortunately is overlooked by even some of our more experienced users. This is a shame since they are in fact one of the most powerful features of Gaia. With Aspects you can create Ajax Images which can be dragged and dropped on your page. You can make any widget resizable, even Buttons and DropDownLists. You can set specific UpdateControls for specific widgets and so on. There is also a video available!

Aspects Ajax Shopping Cart

The above screenshot is from our Ajax Shopping Cart sample which demonstrates how to make a shopping cart by utilizing Gaia.WebWidgets.AspectDraggable and Gaia.WebWidgets.AspectDroppable.

You can even combine Aspects together and have multiple ones modify the same widget like we're doing in our Dynamic Ajax Image Sample.

ASPX Page <%@ Page Language="C#" AutoEventWireup="true" ClassName="_Default" %>

<%@ Register Assembly="Gaia.WebWidgets" TagPrefix="gaia" Namespace="Gaia.WebWidgets" %>



Ajax Sample


C# Codebehind protected void Page_Load(object sender, EventArgs e) { lbl.Aspects.Add(new Gaia.WebWidgets.AspectDraggable()); }

The above code will create a Label with some style changes to make it "stand out" where you can actually drag and drop the label around on the screen exactly as you wish.

Every Gaia Ajax Widgets have a special "AspectCollection" as a property. This is the same for all Widgets and is called "Aspects". By adding Aspects into this collection the aspects will be rendered clients-side and will modify the behavior of your widget.

Note that if you create Aspects which have event handlers being set, like for instance you instantiate an AspectDraggable and you're handling the Dragged event for it. Then you need to make sure that the Aspect is being RE-added on every single Ajax Callback or Postback since else your event handler won't run. Remember that HTTP is stateless, and all though we could have abstracted this away, we would then have had to use the ViewState for it which really would be exploiting the ViewState from our point of view.

The above code re-adds the AspectDraggable in fact correctly, meaning if you extended the above code to handle the Clicked event and still kept all the rest of the code as it is, it would work. This is because in the above code the AspectDraggable is being added in the Page_Load method every time we get back into the Page Life Cycle which means it will work

ScrewTurn Wiki version 2.0.33. Some of the icons created by FamFamFam.