Monday, August 21, 2006

Understanding Atlas Extenders

I'm not here to offer a brilliant new view on what an Extender is, but I feel my lack of higher education sometimes leaves me scratching my heads on Microsoft’s explanation of their good work, so I’m here to give an easy example of what an Atlas extender does for you.

What is it?
.net has a great feature in extensibility. What is this? It means that if you write a new effect you can implement it on controls that don't have that functionality. The best example in winforms is the ToolTip. Before you drop a ToolTip on a form, you have no way of having hints, but once you've dropped one on a form, all your controls suddenly have a "ToolTip on toolTip1" property where you can add a hint.

An Atlas extender does a similar thing for web controls. It adds properties onto your web controls, to allow special AJAX or javascript effects without needing inheritance or anything complex to work.

How does it help me?
Generally Atlas extenders are at their most useful when there is a nice javascript feature you have, but you want to attach it to your asp.net web controls. Rather than inheriting controls to add javascript niceness, you simply write an extender and use it on what controls you want to.

Pros?

  • There is nothing stopping you writing your own, but Microsoft has already gathered over 20 different extenders written by various authors. This is available for download in the Atlas toolkit http://atlas.asp.net/atlastoolkit/.
    This alone makes Atlas a compelling argument. Imagine that every decent extender that gets written gets added to the Atlas toolkit. By this time next year we could have 100 controls, which any user can access by simply downloading the toolkit.
  • After writing the extender, you can get javascript features in your web controls without writing a line of javascript code. This is nice as feature rich controls come without writing complex javascript code in your web form. The less code on the main page the better.
  • Another nice feature is you can see which Atlas extenders have been added to your web control in the Properties section. Compare this with trying to dig through javascript to see which control a certain web control that function effects and you’ll realise the Atlas extender way is much neater.
  • You can add extender properties in server side code (code behind). Very nice.

Cons?

  • I’m not an expert here, but it seems to me that as the toolkit grows, so will the size of the included toolkit dll, and therefore slow down initial page loads at a new site. This of course isn’t a downside of extenders, but the toolkit itself.
  • Also the extenders don’t work on html controls like a div (from what I’ve seen), so you’re stuck using the asp version of that control, which can make it harder to get extra javascript functionality sometimes.
  • From what I’ve seen you can’t add the extender properties to a control in the design view, but once they’re added you can see them there. (at least this isn't working on my Web Developer Express)
  • On the other hand you can't see the extender properties in the source view.

Example
I’ll give a simple example here, because I’ll probably go through a lot of these controls in more detail later on. For now I’ll show the simplest example. It will extend an asp:Button to include a confirmation dialog using the ConfirmButtonExtender:

  1. Add an Atlas ScriptManager to the form.
  2. Drag a ConfirmButtonExtender onto a web form.
  3. Dragging this adds a simple extender tag. All extender tags have a list of property tags within them to attach an extender to a control and give it other properties.
  4. Drag an asp:Button onto the web form. Call it “AtlasBtn”.
  5. Goto the Source view and find the ConfirmButtonExtender.
  6. Start adding a new tag in the middle of that tag by pressing “<”. IntelliSense should kick in and show cc1:ConfirmButtonProperties
  7. Add properties in there for ConfirmText (like "Are you really sure?") and TargetControlID="AtlasBtn".

That’s all there is to it. Now when the user clicks on that button, the server side code on AtlasBtn will only execute once the user confirms the dialog, otherwise nothing will happen. Note also that when clicking on AtlasBtn in the Design view now, the properties show the Atlas Extender

Full code:




<%@ Page Language="C#" %>

<%@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void AtlasBtn_Click(object sender, EventArgs e)
{
Response.Write("Added this text through server side code now.");
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Atlas Extender example</title>
</head>
<body>
<atlas:ScriptManager ID="scriptmgr" runat="server" />
<form id="form1" runat="server">
<div>
<asp:Button ID="AtlasBtn" runat="server" Text="Click to add" OnClick="AtlasBtn_Click" />
</div>
</form>
<cc1:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server">
<cc1:ConfirmButtonProperties ConfirmText="Are you really sure?" TargetControlID="AtlasBtn" />
</cc1:ConfirmButtonExtender>
</body>
</html>

kick it on DotNetKicks.com

2 comments:

Anonymous said...

Extenders are a really nice feature. Just imagine what would happen if there was a set of completly new controls every time a new feature hits the market :-o

xxx erotic sex stories said...

I stay around forabout 30 more minutes taking bits of film then head home. After she closes her eyes, I slip a blindfold on her and tell her not tomove.
teen camping sex stories
interracial wife stories
gay teen male sex stories
boy interracial stories
illustrated erotic stories
I stay around forabout 30 more minutes taking bits of film then head home. After she closes her eyes, I slip a blindfold on her and tell her not tomove.