Atlas is not just the UpdatePanel! - Here's a simple Atlas Client Script example to prove it!

Most of the examples you see out there regarding Atlas involve wrapping the UpdatePanel around something, adding some triggers and seeing the magic.

That is great, but Atlas has more to offer than that because it offers a 1)whole client side framework that makes writing on the client so much nicer for those of you coming from a .net background and 2)Control Extenders that make your server side controls perform client side magic. 

Heres an example of the client stuff.  For more information on the control extenders checkout the toolkit.

Creating a Page to Display a Random Quote

Lets say you have been asked to create a web page to show a daily quote.  The information will be provided via a web service with the following method:

  • GetQuote() - returns an object with a QuoteText, Author and Url property with details of a random quote.

Displaying the Quote

  • Users should click a link on the page to display the quote.  The Author property should be displayed as a hyperlink using using the Url.

e.g.: This is the quote - Author 

  • Users should be able to change the style of the quote using a dropdownlist with the following values: small, medium, large.  Selecting this should apply a style to the quote.
  • Users should be able to make a new quote show automatically every 5 seconds if they like.

OK so lets run through this using Atlas controls...

Adding the Script Manager

First add the script manager to the page:

<atlas:ScriptManager ID="ScriptManager1" runat="server">

<Services>

<atlas:ServiceReference Path="QuoteService.asmx" />

</Services>

</atlas:ScriptManager>

We have added a reference to our QuoteService.asmx web service in the script manager.  The script manager is the only server control we are using here.

Laying Out the Page

Next lets layout the page:

<div>

<select id="StyleSelect">

<option value="small">Small</option>

<option value="medium" selected="selected">Medium</option>

<option value="large">Large</option>

</select>

<a href="#" id="HyperLink1" >Get Quote</a>

<input id="Checkbox1" type="checkbox" /> Auto Quote (every 5 seconds)

<br />

<br />

<span id="QuoteText"></span><a id="AuthorHyperLink"></a>

</div>

Ok that gives us a very basic layout to use:  

Lets add some basic styles too:

<style type="text/css">

.small

{

font-size:.7em;

}

.medium

{

font-size: 1.5em;

}

.large

{

font-size: 2em;

}

</style>

Creating the Client Side Code

Now to create the client side code:

I am going to create some vars and then initialise them in a pageLoad event that Atlas provides (add the following in a <script type="text/javascript"></script> block)

var styleSelect;

var hyperLink1;

var authorHyperLink;

var quoteText;

var timer;

var checkBox1;

function pageLoad()

{

hyperLink1 = new Sys.UI.HyperLink($('HyperLink1'));

hyperLink1.initialize();

hyperLink1.click.add(getQuote);

styleSelect = new Sys.UI.Select($('StyleSelect'));

styleSelect.initialize();

styleSelect.selectionChanged.add(changeStyle);

quoteText = new Sys.UI.Label($('QuoteText'));

authorHyperLink = new Sys.UI.HyperLink($('AuthorHyperLink'));

timer = new Sys.Timer();

timer.initialize();

timer.set_interval(5000);

timer.tick.add(timerTick);

timer.set_enabled(false);

checkBox1 = new Sys.UI.CheckBox($('CheckBox1'));

checkBox1.initialize();

checkBox1.click.add(checkBox1Clicked);

}

You'll notice a few things here:

  • Using the $ is an Atlas shortcut for getElementById
  • I am creating objects from these elements.  And these objects are part of the client Sys.UI namespace that Atlas provides. (e.g. hyperLink1 = new Sys.UI.HyperLink($('HyperLink1'));
  • These objects have their own Atlas properties, methods and events (see http://atlas.asp.net/docs/Client/default.aspx for full reference), so I can do things like the following to wire up an event:

    hyperLink1.click.add(getQuote);

Calling the Web Service

Lets have a look at how we get the quote.  The following is the mocked method to deliver the quote:

[WebMethod]

public Quote GetRandomQuote()

{

Random rnd = new Random();

Quote quote = new Quote();

quote.Author = "Fred " + rnd.Next(100).ToString();

quote.QuoteText = "Some Quote " + rnd.Next(100).ToString();

quote.Url = "http://" + rnd.Next(100).ToString();

return quote;

}

and the quote class is simply:

public class Quote

{

private string _quoteText;

public string QuoteText

{

get

{

return _quoteText;

}

set

{

_quoteText = value;

}

}

private string _author;

public string Author

{

get

{

return _author;

}

set

{

_author = value;

}

}

private string _url;

public string Url

{

get

{

return _url;

}

set

{

_url = value;

}

}

}

When we add a reference to the script manager (as we did above) then we get proxy classes to call the web service for free - so we can do the following:

function getQuote()

{

QuoteService.GetRandomQuote(randomQuoteComplete);

}

 

function randomQuoteComplete(result)

{

authorHyperLink.set_text(result.Author);

authorHyperLink.set_navigateURL(result.Url);

quoteText.set_text(result.QuoteText + " - ");

}

You'll notice here that

  • there is a callback which is called when the method is complete.  You can also add callbacks for errors, timeouts and cancel (see http://atlas.asp.net/docs/atlas/doc/services/consuming.aspx for full details of consuming web services on the client).
  • The complex type (ie. Quote) is returned and we can access it's properties using the familiar dot notation (result.Author)

Using the Timer Class

This is very simple.  We just need to enable the timer when the checkbox is clicked (we have already set up the event handler for this in the pageLoad event), then call getQuote() on every tick the timer generates:

function checkBox1Clicked()

{

timer.set_enabled(checkBox1.get_checked());

}

function timerTick()

{

getQuote();

}

Applying Styles to the Quote

The Atlas client library controls all come with classes that let you work with Css (http://atlas.asp.net/docs/Client/Sys.UI/Control/default.aspx).  Since we have already wired up the selectionChanged event for the dropdownlist to a changeStyle method, we can do the following:

function changeStyle()

{

var styleName = styleSelect.get_selectedValue();

authorHyperLink.set_cssClass(styleName);

}

OK that's it.  Hopefully that has demonstrated some of the features of the Atlas client library.  There are of course many more things you can do.  For example:

  • Data Binding
  • Declarative mark-up using Xml-Script instead of  using javascript
  • Behaviours (e.g AutoComplete behaviour)

Check out the docs for more details

HTH

Ian

posted @ Friday, July 14, 2006 10:23 AM

Print

Comments on this entry:

# Link buy cialis cheap.

Left by Phorum ask a forester buy cialis. at 5/30/2008 3:56 AM
Gravatar
Buy cialis. Cialis best price buy online. Buy cialis mg x in us online pharmacy.

# Forced sex.

Left by Forced sex. at 6/21/2008 9:33 AM
Gravatar
Forced sex.

# vklnseee

Left by vklnseee at 7/10/2008 12:52 AM
Gravatar
vklnseee

# tllabkrp

Left by tllabkrp at 7/12/2008 9:04 AM
Gravatar
tllabkrp

# jcbicvfw

Left by jcbicvfw at 7/12/2008 9:05 AM
Gravatar
jcbicvfw

# vyzmveho

Left by vyzmveho at 7/12/2008 9:05 AM
Gravatar
vyzmveho

# uwcrmagh

Left by uwcrmagh at 7/12/2008 9:06 AM
Gravatar
uwcrmagh

# xrqcpjqj

Left by xrqcpjqj at 7/12/2008 9:06 AM
Gravatar
xrqcpjqj

# pnnzxfhd

Left by pnnzxfhd at 7/12/2008 9:06 AM
Gravatar
pnnzxfhd

# ihcjnlod

Left by ihcjnlod at 7/12/2008 9:07 AM
Gravatar
ihcjnlod

# adqutcrw

Left by adqutcrw at 7/12/2008 9:40 AM
Gravatar
adqutcrw

# infhmwgi

Left by infhmwgi at 7/12/2008 9:40 AM
Gravatar
infhmwgi

# gsltibgk

Left by gsltibgk at 7/14/2008 7:21 PM
Gravatar
gsltibgk

# ovoyhhwt

Left by ovoyhhwt at 7/14/2008 7:21 PM
Gravatar
ovoyhhwt

# imqdzaun

Left by imqdzaun at 7/14/2008 7:21 PM
Gravatar
imqdzaun

# tofmfaka

Left by tofmfaka at 7/14/2008 7:21 PM
Gravatar
tofmfaka

# raxhwsrl

Left by raxhwsrl at 7/17/2008 4:28 AM
Gravatar
raxhwsrl

# iroyjbxb

Left by iroyjbxb at 7/17/2008 4:28 AM
Gravatar
iroyjbxb

# sxpvkfzi

Left by sxpvkfzi at 7/17/2008 4:28 AM
Gravatar
sxpvkfzi

# Dog sex pics.

Left by Dog sex. at 7/21/2008 11:04 AM
Gravatar
Disney porn great free porn movies and dog sex.

# znxnvjfv

Left by znxnvjfv at 8/25/2008 9:36 PM
Gravatar
znxnvjfv

# wipxqbjw

Left by wipxqbjw at 9/16/2008 12:23 PM
Gravatar
wipxqbjw

# ghshkfee

Left by ghshkfee at 9/16/2008 12:24 PM
Gravatar
ghshkfee

# zjypcspd

Left by zjypcspd at 9/16/2008 12:24 PM
Gravatar
zjypcspd

# zrqqlamn

Left by zrqqlamn at 9/16/2008 12:24 PM
Gravatar
zrqqlamn

# hnhngvai

Left by hnhngvai at 9/16/2008 12:24 PM
Gravatar
hnhngvai

# sdtaalol

Left by sdtaalol at 9/16/2008 12:24 PM
Gravatar
sdtaalol

# generic cialis

Left by generic cialis at 9/18/2008 1:15 PM
Gravatar
generic cialis

# whwgxzri

Left by whwgxzri at 9/18/2008 8:22 PM
Gravatar
whwgxzri

# nhxzramr

Left by nhxzramr at 9/18/2008 8:22 PM
Gravatar
nhxzramr

# tznanlbq

Left by tznanlbq at 9/18/2008 8:23 PM
Gravatar
tznanlbq

# eysjdlyz

Left by eysjdlyz at 9/21/2008 4:46 AM
Gravatar
eysjdlyz

# apgheofo

Left by apgheofo at 9/21/2008 4:47 AM
Gravatar
apgheofo

# generic zoloft

Left by generic zoloft at 9/23/2008 6:15 AM
Gravatar
generic zoloft

# Fda approved ephedra for.

Left by Ephedra lafayette la. at 7/8/2009 6:59 AM
Gravatar
Ephedra based. Ephedra products. Ephedra. Ephedra ban illegal to posses.

# Phentermine.

Left by Phentermine. at 7/9/2009 10:45 PM
Gravatar
Phentermine 37 5mg. Phentermine info. Phentermine. Phentermine no prescription. Phentermine weight loss.

# Xanax.

Left by Xanax without a prescription. at 7/10/2009 10:54 PM
Gravatar
Xanax dosage. Beer and xanax. Xanax norx needed one day fedex overnight delivery. Xanax. Xanax without prescription.

# Generic viagra.

Left by Cheap viagra. at 7/11/2009 10:46 PM
Gravatar
Viagra. Your viagra onlinne guide.

# Tramadol.

Left by Tramadol. at 7/12/2009 11:11 PM
Gravatar
Cheap tramadol. Buy tramadol. Tramadol. Comparative potencies of opioids tramadol.

# Percocet.

Left by Generic percocet. at 7/15/2009 11:19 PM
Gravatar
Buy percocet online. Percocet high blood pressure. Percocet.

# Tramadol.

Left by Tramadol. at 7/18/2009 12:48 AM
Gravatar
Tramadol cheap no rx free overnight shipping.

# Vicodin detox.

Left by Forum vicodin buy vicodin online. at 7/18/2009 11:37 PM
Gravatar
How long does vicodin withdrawal last. Vicodin. Vicodin no prescription. Vicodin and no consults and no prescription. Vicodin detox vicodin. Buy vicodin without script. Vicodin no prior prescription. Vicodin overdose.

# Lortab and pregnancy.

Left by Lortab. at 8/8/2009 6:02 AM
Gravatar
Lortab. Buy lortab in our online pharmacies.

# Carisoprodol addiction.

Left by Carisoprodol addiction. at 8/8/2009 7:21 PM
Gravatar
Soma carisoprodol you can found more info here. Carisoprodol phentermine yellow all on one site.

# Meridia.

Left by Meridia for sale. at 8/9/2009 8:32 AM
Gravatar
Meridia. Meridia without prescriptions. Meridia for sale.

# Doxycycline 100.

Left by Doxycycline hyclate 100 mg. at 8/9/2009 12:36 PM
Gravatar
Doxycycline helps most female acne. Doxycycline gpnotebook. Doxycycline.

# Diazepam 5mg.

Left by Diazepam. at 8/9/2009 2:56 PM
Gravatar
Diazepam 5mg. Diazepam.

# Buy tramadol the lowest prices chtiblog com.

Left by Buy tramadol. at 8/9/2009 6:03 PM
Gravatar
Activado agcode buy tramadol icqwebmail info. Buy tramadol the lowest prices chtiblog com. Buy tramadol.

# Butalbital 50.00 90 tabs free shipping.

Left by Side effects of butalbital. at 8/10/2009 4:14 AM
Gravatar
Butalbital order online. Butalbital order. Snort and butalbital. Butalbital. Melatonin acne scar treatment butalbital. Side effects of butalbital.

# White tramadol with 377 on the side.

Left by Tramadol. at 8/10/2009 4:27 AM
Gravatar
Tramadol cod. Tramadol.

# Clonazepam.

Left by Buy clonazepam online no prescription. at 8/10/2009 8:37 PM
Gravatar
Overdose of clonazepam. Clonazepam. 1 day late clonazepam darvocet.

# Buy vicodin.

Left by Buy vicodin. at 8/11/2009 5:01 AM
Gravatar
Buy vicodin.

# Buy viagra.

Left by Buy viagra. at 8/11/2009 6:08 PM
Gravatar
Buy viagra.

# Buy percocet without a prescription.

Left by Buy percocet. at 8/12/2009 12:13 AM
Gravatar
Buy percocet. Buy percocet online. Buy percocet online no prescription. Buy percocet online without office visit.

# Buy soma online without rx.

Left by Buy soma tablets. at 8/12/2009 3:51 AM
Gravatar
Buy soma cod. Buy soma www scantips com buy soma online. Buy soma online. Buy soma watson brand online 150 tablets. Buy soma bloghoster. Buy domain onlinevcvpl soma. Buy soma from mexico online. Http pills.viptemplates.com p buy soma.

# Ativan.

Left by Ativan. at 8/12/2009 9:02 AM
Gravatar
Ativan.

# caused level thousand home peter

Left by caused level thousand home peter at 10/3/2009 8:28 AM
Gravatar
thermohaline likely indicates observed high pre attributed

# depends frequency code world

Left by depends frequency code world at 10/12/2009 2:07 PM
Gravatar
scientific keep record adjust cap amount overwhelming seen

# times result 1960 contributed growing

Left by times result 1960 contributed growing at 10/27/2009 7:12 PM
Gravatar
twentieth paper kyoto possibly increased 100

# gross institute frequency values beta

Left by gross institute frequency values beta at 11/8/2009 10:34 AM
Gravatar
environmental trend weathering announced heat 1950 times

# simulations system projections 1950

Left by simulations system projections 1950 at 11/17/2009 11:14 PM
Gravatar
1998 debate state wide report

# century records email

Left by century records email at 11/27/2009 10:34 AM
Gravatar
estimate impact tonne retreat affected issues global

# Buy tramadol online.

Left by Buy tramadol cheap medication 35009. at 1/11/2010 1:35 AM
Gravatar
Buy tramadol. Buy cheap tramadol.

# available against

Left by available against at 5/19/2010 7:29 AM
Gravatar
societies president extinctions running issue impact beginning

# figure frozen activity effects compared

Left by figure frozen activity effects compared at 8/31/2010 8:00 AM
Gravatar
required down indicates
Comments have been closed on this topic.
«September»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789