Adding Controls
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.
Figure 15-3. Dragging buttons onto the Web Form
You can add controls to a page in one of two modes. The default mode
is GridLayout
. When you add
controls in GridLayout
, they are arranged in the
browser using absolute positioning (x and y coordinates).
The alternative mode ...
Get Programming C#, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.