You can add server-side controls to a Web
Form in two ways: manually, by
writing HTML
into the HTML page, or by dragging controls from the toolbox to the
Design page. For example, suppose you want to use buttons to let the
user choose one of three Shippers provided in the Northwinds
database. You could write the following HTML into the
<form>
element in the HTML window:
<asp:RadioButton GroupName="Shipper" id="Airborne" text = "Airborne Express" Checked="True" runat="server"> </asp:RadioButton> <asp:RadioButton GroupName="Shipper" id="UPS" text = "United Parcel Service" runat="server"> </asp:RadioButton> <asp:RadioButton GroupName="Shipper" id="Federal" text = "Federal Express" runat="server"> </asp:RadioButton>
The asp
tags declare server-side
ASP.NET controls that are replaced with
normal HTML when the server processes the page. When you run the
application, the browser displays three radio buttons in a button
group; pressing one will deselect the others.
You can create the same effect more easily by dragging three buttons from the Visual Studio toolbox onto the Form, as illustrated in Figure 15-3.
You can add controls to a page in one of two modes. The default mode
is LinearLayout
. When you
add controls in LinearLayout
, they are displayed
by the browser one after the other. You are responsible for adding
HTML to assist in their positioning.
The alternative mode is
GridLayout
. With
GridLayout
, the controls are added to a grid,
allowing for more accurate positioning. When you turn on
GridLayout
, the wizard adds a table to your page
to allow for precise positioning. To change from Grid to Layout or
back, change the
pageLayout
property
of the document in Visual Studio .NET.
GridLayout
makes the HTML a bit more difficult to
read, but it does make it easier to place controls precisely where
you want them and thus to create attractive pages. We’ll stick
to LinearLayout
for now to keep the HTML simple.
Web Forms offer two types of server-side controls. The first type is
server-side HTML controls, also called Web Controls. These are
standard HTML controls that you tag with the attribute
runat=Server
.
The alternative to Web Controls is ASP.NET Server Controls, also called ASP Controls. ASP Controls have been designed to replace the standard HTML controls. ASP controls provide a more consistent object model and more consistently named attributes. For example, with HTML controls, there are myriad different ways to handle input:
<input type = "radio"> <input type="checkbox"> <input type="button"> <input type="text"> <textarea>
Each of these behaves differently and takes different attributes. The ASP Controls try to normalize the set of controls, using attributes consistently throughout the ASP control object model. The ASP Controls that correspond to the preceding HTML server-side controls are:
<asp:RadioButton> <asp:CheckBox> <asp:Button> <asp:TextBox rows="1"> <asp:TextBox rows="5">
18.191.205.99