Professional Documents
Culture Documents
NET application
This is a screenshot of an ASP.NET application:
TextBox1
Button1
RadioButtonList1
RadioButtonList2
Label1
The application should have the following functionality: When the user clicks on Button1, the text in TextBox1 is moved to Label1. When the user clicks on an item in RadioButtonList1, Label1s foreground text color is changed to the color that corresponds to that item. When the user clicks on an item in RadioButtonList2, Label1s background text color is changed to the color that corresponds to that item.
The (incomplete) code for the application (Default.aspx.cs) is on the next page.
First, you should download the (incomplete) solution from the MIS Community Site.
Now start by answering the questions on page 3.
using using using using using using using using using using
System; System.Data; System.Configuration; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Web.UI.HtmlControls; System.Drawing;
public partial class _Default : System.Web.UI.Page { string[] colorlabels = { "Red", "Green", "Blue", "Yellow", "Orange", "Black" }; Color[] colors = { Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Orange, Color.Black }; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { populateRadio(); } } private void populateRadio() { for(int i = 0; i < colorlabels.Length; i++) { ListItem colorItem = new ListItem(colorlabels[i], i.ToString()); RadioButtonList1.Items.Add(colorItem); RadioButtonList2.Items.Add(colorItem); } } protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) {
} }
Part I: Some initial questions about the code (Default.aspx.cs) 1) What data type are the elements of the colorLabels array?
What do you think the elements in the colors array represent (i.e., What is Color.Red)?
3) Explain in a few sentences (or bullet points) what each statement is doing in the populateRadio() method.
Part II: Complete the code In Visual Studio, complete the code for the RadioButtonList1_SelectedIndexChanged(), RadioButtonList2_SelectedIndexChanged(), and the Button1_Click() methods, given the following information: Label1.Text Label1.ForeColor Label1.BackColor Property containing the visible text for the Label1 object (a string object) Property containing the foreground color for the Label1 object (a Color object) Property containing the background color for the Label1 object (a Color object)
Part III: Answer some questions about the web page (Default.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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>Untitled Page</title> </head><body> <form id="form1" runat="server"><div> Label text: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Change label text" /><br /> <br /> <table border="0"> <tr> <td style="height: 47px"> Foreground Color</td> <td style="height: 47px"> Background Color</td> </tr><tr><td> <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged= "RadioButtonList1_SelectedIndexChanged" Width="134px"> </asp:RadioButtonList></td> <td> <asp:RadioButtonList ID="RadioButtonList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged= "RadioButtonList2_SelectedIndexChanged" Width="134px"> </asp:RadioButtonList></td></tr> </table></div><br /> <asp:Label ID="Label1" runat="server" Font-Size="Large" Text="Sample Text" Width="170px"></asp:Label> <br /><br /> </form></body></html>
You can open up the HTML for Default.aspx in Visual Studio by double-clicking on Default.aspx and then clicking on the Source tab.
2) Now, try changing this part of the RadioButtonList1 tag: OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" to this: OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChangedABC" What happens when you compile the program? Why?