Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
Understanding Web Controls for Selecting Choices in Delphi ASP.NET Applications
Page 1: RadioButton, CheckBox
 More of this Feature
• Page 2: RadioButtonList, CheckBoxList
• Page 3: ListBox, DropDownList
 Join the Discussion
"Post your views and comments to this chapter of the free Asp.Net Delphi Programming Course"
Discuss!
 Related Resources
• A Beginner's Guide to Asp.Net Programming for Delphi developers.TOC

Welcome to the fifteenth chapter of the FREE online programming course:
A Beginner's Guide to Asp.Net Programming for Delphi developers.
ASP.NET selection controls allow users to select from a series of predefined values. This chapter explores list-type controls: CheckBox, CheckBoxList, RadioButton, RadioButtonList, DropDownList and ListBox from the perspective of a Delphi ASP.NET web developer.

In the Introduction to Web Server Controls chapter, we've divided ASP.NET Web Server controls into several categories.
We continue our exploration of the System.Web.UI.WebControls namespace by investigating a variety of different controls that allow selection.

Throughout this chapter, you'll learn about the following:

  • How to enable users to make selections on a Web Form
  • Using RadioButtons and CheckBox
  • Using RadioButtonsList and CheckBoxList
  • Using ListBox and DropDownList
  • Selections in Web Forms
    Much similar to Win32 applications, a Web application must enable a user to select a value from a predefined set. Starting with individual controls, we have the CheckBox (in Win32: TCheckBox), RadioButton (in Win32: TRadioButton), and then we have group versions of the same controls: the CheckBoxList (in Win32: CheckListBox) and RadioButtonList (in Win32 TRadioGroup).
    There are also the ListBox (in Win32: TListBox) and DropDownList (in Win32: TComboBox with Style := csDropDownList).

    Many of these controls share the same set of features - though each offers a slightly different functionality and look.

    CheckBox
    Much similar to the (Win32) TCheckBox Delphi VCL component, the CheckBox allows Boolean (true/false) selection by the user - user can check the box to select the option, or uncheck it to deselect the option. The Checked property specifies whether the check box is checked.
    The most important event for the CheckBox control is CheckedChanged. Much similar to the TextBox's TextChanged property, after a postback, if the value (Checked) of the control has changed, the CheckedChanged event is raised.

    When you drop a CheckBox control on a Web Form, the generated HTML in the "aspx" view will look like:

    <asp:checkbox id=CheckBox1
      runat="server">
    </asp:checkbox>
    

    The CheckBox control renders as an HTML <input type="checkbox"> element to the browser.
    A CheckBox can have a label (Text property determines the text displayed) that renders "near" the CheckBox depending on the TextAlign property.

    RadioButton
    Again, similar to the TRadioButton, the RadioButton ASP.NET control can operate in groups. OptionButton's GroupName property determines the group name. Several option buttons sharing the same group are mutually exclusive - meaning that only one choice can be selected.

    When you drop a RadioButton control on a Web Form, the generated HTML in the "aspx" view will look like:

    <asp:radiobutton id=RadioButton1
      runat="server">
    </asp:radiobutton>
    

    The RadioButton control renders as an HTML <input type="radio"> element to the browser.

    An example
    Here's one funny example to understand how CheckBox and RadioButton web control operate.
    Drop 3 radio buttons on a web form, and one Check Box. Set the AutoPostback property of the check box to true, and handle the CheckedChanged event:

    procedure TWebForm5.CheckBox1_CheckedChanged
              (sender: System.Object; e: System.EventArgs);
    begin
      if CheckBox1.Checked then
      begin
        RadioButton1.GroupName := 'GroupA';
        RadioButton2.GroupName := 'GroupA';
        RadioButton3.GroupName := 'GroupA';
      end
      else
      begin
        RadioButton1.GroupName := '';
        RadioButton2.GroupName := '';
        RadioButton3.GroupName := '';
      end;
    end; //CheckBox1_CheckedChanged
    

    Option buttons and check boxes

    When the check box is on, only one option button can be selected - all three option buttons share the same Group.
    When the Checked property oh the check box is false ("not checked") you can select all three option buttons (since the code clears the GroupName property).

    Next page > RadioButtonList, CheckBoxList > Page 1, 2, 3

    A Beginner's Guide to ASP.NET Programming for Delphi developers: Next Chapter >>
    >> TOC

    Explore Delphi Programming

    About.com Special Features

    Build Your Own Website

    Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

    Connect Your Home Computers

    Easy ways to connect two computers for networking purposes. More >

    Delphi Programming

    1. Home
    2. Computing & Technology
    3. Delphi Programming

    ©2009 About.com, a part of The New York Times Company.

    All rights reserved.