Delving Deeper into Atlas Client Controls - Hyperlinks
(Page 2 of 4 )
In HTML, the <a> element is used to link to other pages and to documents, and it is also for bookmarks. In Atlas, hyperlinks are represented with theSys.UI.HyperLinkclass. This class implements theget_navigateURL()andset_navigateURL()methods for setting the link target (only the target URL, not the target frame or window). It also provides aclickevent, which can be acted upon. (Event handling is covered later in this chapter in the
“Handling Control Events” section.)
In Example 4-4, an empty link (<a></a>) is created, and a link target is added dynamically. In the example, the link is the same Atlas logo image that you used in the preceding example.
It is not possible to directly set the text of the link. A link might not necessarily be a text link, but could also contain an image or another element. Therefore, the text of the link can be thought of as another object, and if you want to set the link text, you have to put another element (with ID) inside the link.
Example 4-4. Using an Atlas Link control
ControlHyperLink.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">
function pageLoad() {
var link = new Sys.UI.HyperLink($("Link1"));
link.set_navigateURL(http://atlas.asp.net/);
var image = new Sys.UI.Image($("Image1"));
image.set_imageURL("atlaslogo.gif");
image.set_alternateText("Atlas logo");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager runat="server">
</atlas:ScriptManager>
<div>
<a id="Link1"><img id="Image1" /></a>
</div>
</form>
</body>
</html>
Figure 4-4 shows the result.

Figure 4-4. An Image control is now a hyperlink
Next: Buttons >>
More ASP.NET Articles
More By O'Reilly Media
|
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.
|
|