Atlas Client Controls - Labels
(Page 4 of 4 )
For the Atlas Label control, Atlas supports the two following additional methods, which are both shown in Example 4-2.
get_text()
Retrieves the current text of the element
set_text()
Sets (changes) the text in the element
Remember that JavaScript and the browser DOM do not offer an equivalent to ASP.NET’sInnerTextproperty. The property that bothget_text()andset_text()are accessing isinnerHTML, so you always have to consider escaping special characters to avoid side effects. This will be covered in Chapter 5.
Example 4-2 does three things:
- It creates the client-sideSys.UI.Labelobject.
- It reads the old text using theget_text()method.
- It writes new text using theset_text()method.
Example 4-2. Using an Atlas Label control
ControlLabel.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Atlas</title>
<script language="JavaScript" type="text/javascript">
window.onload = function(){
var label = new Sys.UI.Label($("Label1"));
var d = new Date();
var time = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
label.set_text(label.get_text() + time);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager runat="server">
</atlas:ScriptManager>
<div>
<span id="Label1">time goes here: </span>
</div>
</form>
</body>
</html>
After the page loads, the current time is determined and then put in the<span>element. Figure 4-2 shows the result.

Figure 4-2. The current time appears in the label
In ordinary JavaScript programming, you setwindow.onloadto an anonymous JavaScript function to be sure that code will be executed only when the HTML markup in the page has been fully loaded. To simplify this, Atlas comes with a convenient feature: if you call an Atlas function namedpageLoad(), the function will execute when the page’sloadevent occurs, first guaranteeing that the Atlas framework has been completely loaded and initialized.
Please check back next week for the continuation of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter four of the book Programming Atlas, written by Christian Wenz (O'Reilly, 2006; ISBN: 0596526725). Check it out today at your favorite bookstore. Buy this book now.
|
|