ASP.NET
  Home arrow ASP.NET arrow Page 4 - Delving Deeper into Atlas Client Controls
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Delving Deeper into Atlas Client Controls
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-04-26

    Table of Contents:
  • Delving Deeper into Atlas Client Controls
  • Hyperlinks
  • Buttons
  • Selection Lists

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Delving Deeper into Atlas Client Controls - Selection Lists


    (Page 4 of 4 )

    HTML selection lists (<select>...</select>) can come in different forms: a drop-down list where the user has to click to see all list elements, or a selection list where some of the elements are already visible. Both types of lists


    Figure 4-5.  Atlas has checked the checkbox

    are covered by Atlas with the Sys.UI.Selectclass. Unlike using JavaScript to work with a<select>element, the ability to set the individual values of the list’s elements is not provided by the Atlas classes.

    If the data for the list exists in the form of a .NETDataTableobject, data binding is a possibility. Chapter 9 explains this approach.

    But we can demonstrate theget_selectedValue()method, which determines thevalue attribute of the currently selected item in the list.

    When sending the form to the server via HTTP GET or POST, it is not essential to set thevalueattribute, because the caption of the element (the text between<option>and</option>) is passed forvalue. However, a list item with novalueproperty is empty in JavaScript. Therefore, you should always set thevalueproperty for all list elements.

    Since event handling isn’t covered until later in this chapter, in Example 4-6, thechange event of the list is not captured, and instead the state of the list is analyzed every second. This is done using thesetInterval()JavaScript function. This polling technique is used only for the sake of the example here; Chapter 5 will cover a much better way to keep two elements in sync, namely through the use of data binding.

      function pageLoad() {
       
    window.setInterval(
         
    function() {
          
    //access the list and output its selected value
         
    },
         
    1000);
      }

    Example 4-6 shows how to use Atlas to check for a current selection and display the selection value in a<span>element (Sys.UI.Label).

    Example 4-6. Using an Atlas Select control

    ControlSelect.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">
      var label;
      var select;

      function pageLoad() {
       
    label = new Sys.UI.Label($("Label1"));
        select = new Sys.UI.Select($("Select1"));

        // Poll every second to determine whether a value has been selected.
        window.setInterval(
          function() {  
           
    label.set_text(select.get_selectedValue());
          },
         
    1000);
      }
      </script>

    </head>
    <body>
      <form id="form1" runat="server">
        <atlas:ScriptManager runat="server">
        </atlas:ScriptManager>
        <div>
         
    <select id="Select1" size="3"
           <option value="1">one</option>
           <option value="2">two</option>
           <option value="3">three</option>
          </select><br />
          Selected value: <label id="Label1"></label>
       
    </div>
     
    </form>
    </body>
    </html>

    Figure 4-6 shows the result.


    Figure 4-6.  The selected value is written to the Label control

    Usingget_selectedValue()may be convenient, but only for regular selection lists. If you are using<select multiple="multiple">, you only get thevalueof the first list element that is selected, not of all selected elements. To check all selected elements, you would need to use Java-Script code to loop through all the items individually, as shown in the following snippet:

      var op = document.forms[0].elements["Select1"].
      options;
      for (var i=0; i < op.length; i++) {
        if (op[i].selected) {
          //element is selected
        } else {
          //element is not selected
        }
      }

    Please check back next week for the conclusion to 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 an excerpt from the book "Programming Atlas," published by O'Reilly....
     

    Buy this book now. 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.

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT